From bcf78a20978d76f64b7cd46d1a4d7a79a578c77b Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Fri, 9 Sep 2011 22:36:31 -0700 Subject: zlib 0.71 --- infutil.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 infutil.c (limited to 'infutil.c') diff --git a/infutil.c b/infutil.c new file mode 100644 index 0000000..92d115f --- /dev/null +++ b/infutil.c @@ -0,0 +1,76 @@ +/* inflate_util.c -- data and routines common to blocks and codes + * Copyright (C) 1995 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "zutil.h" +#include "inftrees.h" +#include "infutil.h" + +struct inflate_codes_state {int dummy;}; /* for buggy compilers */ + +/* And'ing with mask[n] masks the lower n bits */ +uInt inflate_mask[] = { + 0x0000, + 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, + 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff +}; + + +/* copy as much as possible from the sliding window to the output area */ +int inflate_flush(s, z, r) +struct inflate_blocks_state *s; +z_stream *z; +int r; +{ + uInt n; + Byte *p, *q; + + /* local copies of source and destination pointers */ + p = z->next_out; + q = s->read; + + /* compute number of bytes to copy as far as end of window */ + n = (q <= s->write ? s->write : s->end) - q; + if (n > z->avail_out) n = z->avail_out; + if (n && r == Z_BUF_ERROR) r = Z_OK; + + /* update counters */ + z->avail_out -= n; + z->total_out += n; + + /* update check information */ + s->check = adler32(s->check, q, n); + + /* copy as far as end of window */ + while (n--) *p++ = *q++; + + /* see if more to copy at beginning of window */ + if (q == s->end) + { + /* wrap source pointer */ + q = s->window; + + /* compute bytes to copy */ + n = s->write - q; + if (n > z->avail_out) n = z->avail_out; + if (n && r == Z_BUF_ERROR) r = Z_OK; + + /* update counters */ + z->avail_out -= n; + z->total_out += n; + + /* update check information */ + s->check = adler32(s->check, q, n); + + /* copy */ + while (n--) *p++ = *q++; + } + + /* update pointers */ + z->next_out = p; + s->read = q; + + /* done */ + return r; +} -- cgit v1.2.3-55-g6feb