annotate lib/zlib/infutil.c @ 1971:e45c277da9f1

Actor::_427102 to Actor::_427102_IsOkToCastSpell
author Grumpy7
date Sat, 26 Oct 2013 00:09:30 -0700
parents 9c0607679772
children
rev   line source
0
Ritor1
parents:
diff changeset
1 /* inflate_util.c -- data and routines common to blocks and codes
Ritor1
parents:
diff changeset
2 * Copyright (C) 1995-1998 Mark Adler
Ritor1
parents:
diff changeset
3 * For conditions of distribution and use, see copyright notice in zlib.h
Ritor1
parents:
diff changeset
4 */
Ritor1
parents:
diff changeset
5
Ritor1
parents:
diff changeset
6 #include "zutil.h"
Ritor1
parents:
diff changeset
7 #include "infblock.h"
Ritor1
parents:
diff changeset
8 #include "inftrees.h"
Ritor1
parents:
diff changeset
9 #include "infcodes.h"
Ritor1
parents:
diff changeset
10 #include "infutil.h"
Ritor1
parents:
diff changeset
11
Ritor1
parents:
diff changeset
12 struct inflate_codes_state {int dummy;}; /* for buggy compilers */
Ritor1
parents:
diff changeset
13
Ritor1
parents:
diff changeset
14 /* And'ing with mask[n] masks the lower n bits */
Ritor1
parents:
diff changeset
15 uInt inflate_mask[17] = {
Ritor1
parents:
diff changeset
16 0x0000,
Ritor1
parents:
diff changeset
17 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
Ritor1
parents:
diff changeset
18 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
Ritor1
parents:
diff changeset
19 };
Ritor1
parents:
diff changeset
20
Ritor1
parents:
diff changeset
21
Ritor1
parents:
diff changeset
22 /* copy as much as possible from the sliding window to the output area */
Ritor1
parents:
diff changeset
23 int inflate_flush(s, z, r)
Ritor1
parents:
diff changeset
24 inflate_blocks_statef *s;
Ritor1
parents:
diff changeset
25 z_streamp z;
Ritor1
parents:
diff changeset
26 int r;
Ritor1
parents:
diff changeset
27 {
Ritor1
parents:
diff changeset
28 uInt n;
Ritor1
parents:
diff changeset
29 Bytef *p;
Ritor1
parents:
diff changeset
30 Bytef *q;
Ritor1
parents:
diff changeset
31
Ritor1
parents:
diff changeset
32 /* local copies of source and destination pointers */
Ritor1
parents:
diff changeset
33 p = z->next_out;
Ritor1
parents:
diff changeset
34 q = s->read;
Ritor1
parents:
diff changeset
35
Ritor1
parents:
diff changeset
36 /* compute number of bytes to copy as far as end of window */
Ritor1
parents:
diff changeset
37 n = (uInt)((q <= s->write ? s->write : s->end) - q);
Ritor1
parents:
diff changeset
38 if (n > z->avail_out) n = z->avail_out;
Ritor1
parents:
diff changeset
39 if (n && r == Z_BUF_ERROR) r = Z_OK;
Ritor1
parents:
diff changeset
40
Ritor1
parents:
diff changeset
41 /* update counters */
Ritor1
parents:
diff changeset
42 z->avail_out -= n;
Ritor1
parents:
diff changeset
43 z->total_out += n;
Ritor1
parents:
diff changeset
44
Ritor1
parents:
diff changeset
45 /* update check information */
Ritor1
parents:
diff changeset
46 if (s->checkfn != Z_NULL)
Ritor1
parents:
diff changeset
47 z->adler = s->check = (*s->checkfn)(s->check, q, n);
Ritor1
parents:
diff changeset
48
Ritor1
parents:
diff changeset
49 /* copy as far as end of window */
Ritor1
parents:
diff changeset
50 zmemcpy(p, q, n);
Ritor1
parents:
diff changeset
51 p += n;
Ritor1
parents:
diff changeset
52 q += n;
Ritor1
parents:
diff changeset
53
Ritor1
parents:
diff changeset
54 /* see if more to copy at beginning of window */
Ritor1
parents:
diff changeset
55 if (q == s->end)
Ritor1
parents:
diff changeset
56 {
Ritor1
parents:
diff changeset
57 /* wrap pointers */
Ritor1
parents:
diff changeset
58 q = s->window;
Ritor1
parents:
diff changeset
59 if (s->write == s->end)
Ritor1
parents:
diff changeset
60 s->write = s->window;
Ritor1
parents:
diff changeset
61
Ritor1
parents:
diff changeset
62 /* compute bytes to copy */
Ritor1
parents:
diff changeset
63 n = (uInt)(s->write - q);
Ritor1
parents:
diff changeset
64 if (n > z->avail_out) n = z->avail_out;
Ritor1
parents:
diff changeset
65 if (n && r == Z_BUF_ERROR) r = Z_OK;
Ritor1
parents:
diff changeset
66
Ritor1
parents:
diff changeset
67 /* update counters */
Ritor1
parents:
diff changeset
68 z->avail_out -= n;
Ritor1
parents:
diff changeset
69 z->total_out += n;
Ritor1
parents:
diff changeset
70
Ritor1
parents:
diff changeset
71 /* update check information */
Ritor1
parents:
diff changeset
72 if (s->checkfn != Z_NULL)
Ritor1
parents:
diff changeset
73 z->adler = s->check = (*s->checkfn)(s->check, q, n);
Ritor1
parents:
diff changeset
74
Ritor1
parents:
diff changeset
75 /* copy */
Ritor1
parents:
diff changeset
76 zmemcpy(p, q, n);
Ritor1
parents:
diff changeset
77 p += n;
Ritor1
parents:
diff changeset
78 q += n;
Ritor1
parents:
diff changeset
79 }
Ritor1
parents:
diff changeset
80
Ritor1
parents:
diff changeset
81 /* update pointers */
Ritor1
parents:
diff changeset
82 z->next_out = p;
Ritor1
parents:
diff changeset
83 s->read = q;
Ritor1
parents:
diff changeset
84
Ritor1
parents:
diff changeset
85 /* done */
Ritor1
parents:
diff changeset
86 return r;
Ritor1
parents:
diff changeset
87 }