Commit 999f677f authored by Linus Torvalds's avatar Linus Torvalds Committed by Russell King

Make zlib_inflate look more like ANSI C code.

Anybody who still thinks K&R makes sense should just be shot.
parent cca66bf2
...@@ -65,10 +65,11 @@ local const uInt border[] = { /* Order of the bit length code lengths */ ...@@ -65,10 +65,11 @@ local const uInt border[] = { /* Order of the bit length code lengths */
*/ */
void zlib_inflate_blocks_reset(s, z, c) void zlib_inflate_blocks_reset(
inflate_blocks_statef *s; inflate_blocks_statef *s,
z_streamp z; z_streamp z,
uLongf *c; uLongf *c
)
{ {
if (c != Z_NULL) if (c != Z_NULL)
*c = s->check; *c = s->check;
...@@ -82,10 +83,11 @@ uLongf *c; ...@@ -82,10 +83,11 @@ uLongf *c;
z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0); z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0);
} }
inflate_blocks_statef *zlib_inflate_blocks_new(z, c, w) inflate_blocks_statef *zlib_inflate_blocks_new(
z_streamp z; z_streamp z,
check_func c; check_func c,
uInt w; uInt w
)
{ {
inflate_blocks_statef *s; inflate_blocks_statef *s;
...@@ -100,10 +102,11 @@ uInt w; ...@@ -100,10 +102,11 @@ uInt w;
} }
int zlib_inflate_blocks(s, z, r) int zlib_inflate_blocks(
inflate_blocks_statef *s; inflate_blocks_statef *s,
z_streamp z; z_streamp z,
int r; int r
)
{ {
uInt t; /* temporary storage */ uInt t; /* temporary storage */
uLong b; /* bit buffer */ uLong b; /* bit buffer */
...@@ -325,19 +328,21 @@ int r; ...@@ -325,19 +328,21 @@ int r;
} }
int zlib_inflate_blocks_free(s, z) int zlib_inflate_blocks_free(
inflate_blocks_statef *s; inflate_blocks_statef *s,
z_streamp z; z_streamp z
)
{ {
zlib_inflate_blocks_reset(s, z, Z_NULL); zlib_inflate_blocks_reset(s, z, Z_NULL);
return Z_OK; return Z_OK;
} }
void zlib_inflate_set_dictionary(s, d, n) void zlib_inflate_set_dictionary(
inflate_blocks_statef *s; inflate_blocks_statef *s,
const Bytef *d; const Bytef *d,
uInt n; uInt n
)
{ {
memcpy(s->window, d, n); memcpy(s->window, d, n);
s->read = s->write = s->window + n; s->read = s->write = s->window + n;
...@@ -348,8 +353,9 @@ uInt n; ...@@ -348,8 +353,9 @@ uInt n;
* by Z_SYNC_FLUSH or Z_FULL_FLUSH. * by Z_SYNC_FLUSH or Z_FULL_FLUSH.
* IN assertion: s != Z_NULL * IN assertion: s != Z_NULL
*/ */
int zlib_inflate_blocks_sync_point(s) int zlib_inflate_blocks_sync_point(
inflate_blocks_statef *s; inflate_blocks_statef *s
)
{ {
return s->mode == LENS; return s->mode == LENS;
} }
...@@ -14,11 +14,13 @@ ...@@ -14,11 +14,13 @@
#define exop word.what.Exop #define exop word.what.Exop
#define bits word.what.Bits #define bits word.what.Bits
inflate_codes_statef *zlib_inflate_codes_new(bl, bd, tl, td, z) inflate_codes_statef *zlib_inflate_codes_new(
uInt bl, bd; uInt bl,
inflate_huft *tl; uInt bd,
inflate_huft *td; /* need separate declaration for Borland C++ */ inflate_huft *tl,
z_streamp z; inflate_huft *td, /* need separate declaration for Borland C++ */
z_streamp z
)
{ {
inflate_codes_statef *c; inflate_codes_statef *c;
...@@ -34,10 +36,11 @@ z_streamp z; ...@@ -34,10 +36,11 @@ z_streamp z;
} }
int zlib_inflate_codes(s, z, r) int zlib_inflate_codes(
inflate_blocks_statef *s; inflate_blocks_statef *s,
z_streamp z; z_streamp z,
int r; int r
)
{ {
uInt j; /* temporary storage */ uInt j; /* temporary storage */
inflate_huft *t; /* temporary pointer */ inflate_huft *t; /* temporary pointer */
...@@ -197,8 +200,9 @@ int r; ...@@ -197,8 +200,9 @@ int r;
} }
void zlib_inflate_codes_free(c, z) void zlib_inflate_codes_free(
inflate_codes_statef *c; inflate_codes_statef *c,
z_streamp z; z_streamp z
)
{ {
} }
...@@ -25,12 +25,14 @@ struct inflate_codes_state; ...@@ -25,12 +25,14 @@ struct inflate_codes_state;
at least ten. The ten bytes are six bytes for the longest length/ at least ten. The ten bytes are six bytes for the longest length/
distance pair plus four bytes for overloading the bit buffer. */ distance pair plus four bytes for overloading the bit buffer. */
int zlib_inflate_fast(bl, bd, tl, td, s, z) int zlib_inflate_fast(
uInt bl, bd; uInt bl,
inflate_huft *tl; uInt bd,
inflate_huft *td; /* need separate declaration for Borland C++ */ inflate_huft *tl,
inflate_blocks_statef *s; inflate_huft *td, /* need separate declaration for Borland C++ */
z_streamp z; inflate_blocks_statef *s,
z_streamp z
)
{ {
inflate_huft *t; /* temporary pointer */ inflate_huft *t; /* temporary pointer */
uInt e; /* extra bits or operation */ uInt e; /* extra bits or operation */
......
...@@ -14,8 +14,9 @@ int ZEXPORT zlib_inflate_workspacesize(void) ...@@ -14,8 +14,9 @@ int ZEXPORT zlib_inflate_workspacesize(void)
} }
int ZEXPORT zlib_inflateReset(z) int ZEXPORT zlib_inflateReset(
z_streamp z; z_streamp z
)
{ {
if (z == Z_NULL || z->state == Z_NULL || z->workspace == Z_NULL) if (z == Z_NULL || z->state == Z_NULL || z->workspace == Z_NULL)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
...@@ -27,8 +28,9 @@ z_streamp z; ...@@ -27,8 +28,9 @@ z_streamp z;
} }
int ZEXPORT zlib_inflateEnd(z) int ZEXPORT zlib_inflateEnd(
z_streamp z; z_streamp z
)
{ {
if (z == Z_NULL || z->state == Z_NULL || z->workspace == Z_NULL) if (z == Z_NULL || z->state == Z_NULL || z->workspace == Z_NULL)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
...@@ -39,11 +41,12 @@ z_streamp z; ...@@ -39,11 +41,12 @@ z_streamp z;
} }
int ZEXPORT zlib_inflateInit2_(z, w, version, stream_size) int ZEXPORT zlib_inflateInit2_(
z_streamp z; z_streamp z,
int w; int w,
const char *version; const char *version,
int stream_size; int stream_size
)
{ {
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
stream_size != sizeof(z_stream) || z->workspace == Z_NULL) stream_size != sizeof(z_stream) || z->workspace == Z_NULL)
...@@ -100,10 +103,11 @@ static int zlib_inflate_packet_flush(inflate_blocks_statef *s) ...@@ -100,10 +103,11 @@ static int zlib_inflate_packet_flush(inflate_blocks_statef *s)
} }
int ZEXPORT zlib_inflateInit_(z, version, stream_size) int ZEXPORT zlib_inflateInit_(
z_streamp z; z_streamp z,
const char *version; const char *version,
int stream_size; int stream_size
)
{ {
return zlib_inflateInit2_(z, DEF_WBITS, version, stream_size); return zlib_inflateInit2_(z, DEF_WBITS, version, stream_size);
} }
...@@ -113,9 +117,10 @@ int stream_size; ...@@ -113,9 +117,10 @@ int stream_size;
#define NEEDBYTE {if(z->avail_in==0)goto empty;r=trv;} #define NEEDBYTE {if(z->avail_in==0)goto empty;r=trv;}
#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++) #define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)
int ZEXPORT zlib_inflate(z, f) int ZEXPORT zlib_inflate(
z_streamp z; z_streamp z,
int f; int f
)
{ {
int r, trv; int r, trv;
uInt b; uInt b;
...@@ -245,8 +250,9 @@ int f; ...@@ -245,8 +250,9 @@ int f;
} }
int ZEXPORT zlib_inflateSync(z) int ZEXPORT zlib_inflateSync(
z_streamp z; z_streamp z
)
{ {
uInt n; /* number of bytes to look at */ uInt n; /* number of bytes to look at */
Bytef *p; /* pointer to bytes */ Bytef *p; /* pointer to bytes */
...@@ -303,8 +309,9 @@ z_streamp z; ...@@ -303,8 +309,9 @@ z_streamp z;
* decompressing, PPP checks that at the end of input packet, inflate is * decompressing, PPP checks that at the end of input packet, inflate is
* waiting for these length bytes. * waiting for these length bytes.
*/ */
int ZEXPORT zlib_inflateSyncPoint(z) int ZEXPORT zlib_inflateSyncPoint(
z_streamp z; z_streamp z
)
{ {
if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL) if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
...@@ -373,8 +380,10 @@ static int zlib_inflate_addhistory(inflate_blocks_statef *s, ...@@ -373,8 +380,10 @@ static int zlib_inflate_addhistory(inflate_blocks_statef *s,
* will have been updated if need be. * will have been updated if need be.
*/ */
int ZEXPORT zlib_inflateIncomp(z) int ZEXPORT zlib_inflateIncomp(
z_stream *z; z_stream *z
)
{ {
if (z->state->mode != BLOCKS) if (z->state->mode != BLOCKS)
return Z_DATA_ERROR; return Z_DATA_ERROR;
......
...@@ -87,17 +87,18 @@ local const uInt cpdext[30] = { /* Extra bits for distance codes */ ...@@ -87,17 +87,18 @@ local const uInt cpdext[30] = { /* Extra bits for distance codes */
/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */ /* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
#define BMAX 15 /* maximum bit length of any code */ #define BMAX 15 /* maximum bit length of any code */
local int huft_build(b, n, s, d, e, t, m, hp, hn, v) local int huft_build(
uIntf *b; /* code lengths in bits (all assumed <= BMAX) */ uIntf *b, /* code lengths in bits (all assumed <= BMAX) */
uInt n; /* number of codes (assumed <= 288) */ uInt n, /* number of codes (assumed <= 288) */
uInt s; /* number of simple-valued codes (0..s-1) */ uInt s, /* number of simple-valued codes (0..s-1) */
const uIntf *d; /* list of base values for non-simple codes */ const uIntf *d, /* list of base values for non-simple codes */
const uIntf *e; /* list of extra bits for non-simple codes */ const uIntf *e, /* list of extra bits for non-simple codes */
inflate_huft * FAR *t; /* result: starting table */ inflate_huft * FAR *t, /* result: starting table */
uIntf *m; /* maximum lookup bits, returns actual */ uIntf *m, /* maximum lookup bits, returns actual */
inflate_huft *hp; /* space for trees */ inflate_huft *hp, /* space for trees */
uInt *hn; /* hufts used in space */ uInt *hn, /* hufts used in space */
uIntf *v; /* working area: values in order of bit length */ uIntf *v /* working area: values in order of bit length */
)
/* Given a list of code lengths and a maximum table size, make a set of /* Given a list of code lengths and a maximum table size, make a set of
tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
if the given code set is incomplete (the tables are still built in this if the given code set is incomplete (the tables are still built in this
...@@ -288,12 +289,13 @@ uIntf *v; /* working area: values in order of bit length */ ...@@ -288,12 +289,13 @@ uIntf *v; /* working area: values in order of bit length */
} }
int zlib_inflate_trees_bits(c, bb, tb, hp, z) int zlib_inflate_trees_bits(
uIntf *c; /* 19 code lengths */ uIntf *c, /* 19 code lengths */
uIntf *bb; /* bits tree desired/actual depth */ uIntf *bb, /* bits tree desired/actual depth */
inflate_huft * FAR *tb; /* bits tree result */ inflate_huft * FAR *tb, /* bits tree result */
inflate_huft *hp; /* space for trees */ inflate_huft *hp, /* space for trees */
z_streamp z; /* for messages */ z_streamp z /* for messages */
)
{ {
int r; int r;
uInt hn = 0; /* hufts used in space */ uInt hn = 0; /* hufts used in space */
...@@ -312,16 +314,17 @@ z_streamp z; /* for messages */ ...@@ -312,16 +314,17 @@ z_streamp z; /* for messages */
return r; return r;
} }
int zlib_inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, hp, z) int zlib_inflate_trees_dynamic(
uInt nl; /* number of literal/length codes */ uInt nl, /* number of literal/length codes */
uInt nd; /* number of distance codes */ uInt nd, /* number of distance codes */
uIntf *c; /* that many (total) code lengths */ uIntf *c, /* that many (total) code lengths */
uIntf *bl; /* literal desired/actual bit depth */ uIntf *bl, /* literal desired/actual bit depth */
uIntf *bd; /* distance desired/actual bit depth */ uIntf *bd, /* distance desired/actual bit depth */
inflate_huft * FAR *tl; /* literal/length tree result */ inflate_huft * FAR *tl, /* literal/length tree result */
inflate_huft * FAR *td; /* distance tree result */ inflate_huft * FAR *td, /* distance tree result */
inflate_huft *hp; /* space for trees */ inflate_huft *hp, /* space for trees */
z_streamp z; /* for messages */ z_streamp z /* for messages */
)
{ {
int r; int r;
uInt hn = 0; /* hufts used in space */ uInt hn = 0; /* hufts used in space */
...@@ -376,12 +379,13 @@ z_streamp z; /* for messages */ ...@@ -376,12 +379,13 @@ z_streamp z; /* for messages */
#include "inffixed.h" #include "inffixed.h"
int zlib_inflate_trees_fixed(bl, bd, tl, td, z) int zlib_inflate_trees_fixed(
uIntf *bl; /* literal desired/actual bit depth */ uIntf *bl, /* literal desired/actual bit depth */
uIntf *bd; /* distance desired/actual bit depth */ uIntf *bd, /* distance desired/actual bit depth */
inflate_huft * FAR *tl; /* literal/length tree result */ inflate_huft * FAR *tl, /* literal/length tree result */
inflate_huft * FAR *td; /* distance tree result */ inflate_huft * FAR *td, /* distance tree result */
z_streamp z; /* for memory allocation */ z_streamp z /* for memory allocation */
)
{ {
*bl = fixed_bl; *bl = fixed_bl;
*bd = fixed_bd; *bd = fixed_bd;
......
...@@ -20,10 +20,11 @@ uInt zlib_inflate_mask[17] = { ...@@ -20,10 +20,11 @@ uInt zlib_inflate_mask[17] = {
/* copy as much as possible from the sliding window to the output area */ /* copy as much as possible from the sliding window to the output area */
int zlib_inflate_flush(s, z, r) int zlib_inflate_flush(
inflate_blocks_statef *s; inflate_blocks_statef *s,
z_streamp z; z_streamp z,
int r; int r
)
{ {
uInt n; uInt n;
Bytef *p; Bytef *p;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment