FreeBSD/Linux Kernel Cross Reference
sys/lib/libz/infutil.c
1 /* $NetBSD: infutil.c,v 1.6 2003/03/25 22:48:44 mycroft Exp $ */
2
3 /* inflate_util.c -- data and routines common to blocks and codes
4 * Copyright (C) 1995-2002 Mark Adler
5 * For conditions of distribution and use, see copyright notice in zlib.h
6 */
7
8 #include "zutil.h"
9 #include "infblock.h"
10 #include "inftrees.h"
11 #include "infcodes.h"
12 #include "infutil.h"
13
14 struct inflate_codes_state {int dummy;}; /* for buggy compilers */
15
16 /* And'ing with mask[n] masks the lower n bits */
17 const uInt inflate_mask[17] = {
18 0x0000,
19 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
20 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
21 };
22
23
24 /* copy as much as possible from the sliding window to the output area */
25 int inflate_flush(s, z, r)
26 inflate_blocks_statef *s;
27 z_streamp z;
28 int r;
29 {
30 uInt n;
31 Bytef *p;
32 Bytef *q;
33
34 /* local copies of source and destination pointers */
35 p = z->next_out;
36 q = s->read;
37
38 /* compute number of bytes to copy as far as end of window */
39 n = (uInt)((q <= s->write ? s->write : s->end) - q);
40 if (n > z->avail_out) n = z->avail_out;
41 if (n && r == Z_BUF_ERROR) r = Z_OK;
42
43 /* update counters */
44 z->avail_out -= n;
45 z->total_out += n;
46
47 /* copy as far as end of window */
48 zmemcpy(p, q, n);
49 p += n;
50 q += n;
51
52 /* see if more to copy at beginning of window */
53 if (q == s->end)
54 {
55 /* wrap pointers */
56 q = s->window;
57 if (s->write == s->end)
58 s->write = s->window;
59
60 /* compute bytes to copy */
61 n = (uInt)(s->write - q);
62 if (n > z->avail_out) n = z->avail_out;
63 if (n && r == Z_BUF_ERROR) r = Z_OK;
64
65 /* update counters */
66 z->avail_out -= n;
67 z->total_out += n;
68
69 /* copy */
70 zmemcpy(p, q, n);
71 p += n;
72 q += n;
73 }
74
75 /* update pointers */
76 z->next_out = p;
77 s->read = q;
78
79 /* done */
80 return r;
81 }
Cache object: 948b15095c589effff44f193718580ef
|