1 /* inflate_util.c -- data and routines common to blocks and codes
2 * Copyright (C) 1995-2002 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
5 * $FreeBSD: src/lib/libz/infutil.c,v 1.1.1.2.6.1 2003/02/01 13:33:12 sobomax Exp $
6 * $DragonFly: src/lib/libz/Attic/infutil.c,v 1.2 2003/06/17 04:26:52 dillon Exp $
15 struct inflate_codes_state {int dummy;}; /* for buggy compilers */
17 /* And'ing with mask[n] masks the lower n bits */
18 uInt inflate_mask[17] = {
20 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
21 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
25 /* copy as much as possible from the sliding window to the output area */
26 int inflate_flush(s, z, r)
27 inflate_blocks_statef *s;
35 /* local copies of source and destination pointers */
39 /* compute number of bytes to copy as far as end of window */
40 n = (uInt)((q <= s->write ? s->write : s->end) - q);
41 if (n > z->avail_out) n = z->avail_out;
42 if (n && r == Z_BUF_ERROR) r = Z_OK;
48 /* update check information */
49 if (s->checkfn != Z_NULL)
50 z->adler = s->check = (*s->checkfn)(s->check, q, n);
52 /* copy as far as end of window */
57 /* see if more to copy at beginning of window */
62 if (s->write == s->end)
65 /* compute bytes to copy */
66 n = (uInt)(s->write - q);
67 if (n > z->avail_out) n = z->avail_out;
68 if (n && r == Z_BUF_ERROR) r = Z_OK;
74 /* update check information */
75 if (s->checkfn != Z_NULL)
76 z->adler = s->check = (*s->checkfn)(s->check, q, n);