/src/skia/third_party/externals/freetype/src/gzip/infutil.c
Line | Count | Source (jump to first uncovered line) |
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 |
4 | | */ |
5 | | |
6 | | #include "zutil.h" |
7 | | #include "infblock.h" |
8 | | #include "inftrees.h" |
9 | | #include "infcodes.h" |
10 | | #include "infutil.h" |
11 | | |
12 | | |
13 | | /* And'ing with mask[n] masks the lower n bits */ |
14 | | local const uInt inflate_mask[17] = { |
15 | | 0x0000, |
16 | | 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, |
17 | | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff |
18 | | }; |
19 | | |
20 | | |
21 | | /* copy as much as possible from the sliding window to the output area */ |
22 | | local int inflate_flush( /* s, z, r) */ |
23 | | inflate_blocks_statef *s, |
24 | | z_streamp z, |
25 | | int r ) |
26 | 0 | { |
27 | 0 | uInt n; |
28 | 0 | Bytef *p; |
29 | 0 | Bytef *q; |
30 | | |
31 | | /* local copies of source and destination pointers */ |
32 | 0 | p = z->next_out; |
33 | 0 | q = s->read; |
34 | | |
35 | | /* compute number of bytes to copy as far as end of window */ |
36 | 0 | n = (uInt)((q <= s->write ? s->write : s->end) - q); |
37 | 0 | if (n > z->avail_out) n = z->avail_out; |
38 | 0 | if (n && r == Z_BUF_ERROR) r = Z_OK; |
39 | | |
40 | | /* update counters */ |
41 | 0 | z->avail_out -= n; |
42 | 0 | z->total_out += n; |
43 | | |
44 | | /* update check information */ |
45 | 0 | if (s->checkfn != Z_NULL) |
46 | 0 | z->adler = s->check = (*s->checkfn)(s->check, q, n); |
47 | | |
48 | | /* copy as far as end of window */ |
49 | 0 | zmemcpy(p, q, n); |
50 | 0 | p += n; |
51 | 0 | q += n; |
52 | | |
53 | | /* see if more to copy at beginning of window */ |
54 | 0 | if (q == s->end) |
55 | 0 | { |
56 | | /* wrap pointers */ |
57 | 0 | q = s->window; |
58 | 0 | if (s->write == s->end) |
59 | 0 | s->write = s->window; |
60 | | |
61 | | /* compute bytes to copy */ |
62 | 0 | n = (uInt)(s->write - q); |
63 | 0 | if (n > z->avail_out) n = z->avail_out; |
64 | 0 | if (n && r == Z_BUF_ERROR) r = Z_OK; |
65 | | |
66 | | /* update counters */ |
67 | 0 | z->avail_out -= n; |
68 | 0 | z->total_out += n; |
69 | | |
70 | | /* update check information */ |
71 | 0 | if (s->checkfn != Z_NULL) |
72 | 0 | z->adler = s->check = (*s->checkfn)(s->check, q, n); |
73 | | |
74 | | /* copy */ |
75 | 0 | zmemcpy(p, q, n); |
76 | 0 | p += n; |
77 | 0 | q += n; |
78 | 0 | } |
79 | | |
80 | | /* update pointers */ |
81 | 0 | z->next_out = p; |
82 | 0 | s->read = q; |
83 | | |
84 | | /* done */ |
85 | 0 | return r; |
86 | 0 | } |