aboutsummaryrefslogtreecommitdiffstats
path: root/lib/zlib_inflate/infutil.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /lib/zlib_inflate/infutil.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'lib/zlib_inflate/infutil.c')
-rw-r--r--lib/zlib_inflate/infutil.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/lib/zlib_inflate/infutil.c b/lib/zlib_inflate/infutil.c
new file mode 100644
index 000000000000..00202b3438e1
--- /dev/null
+++ b/lib/zlib_inflate/infutil.c
@@ -0,0 +1,88 @@
1/* inflate_util.c -- data and routines common to blocks and codes
2 * Copyright (C) 1995-1998 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6#include <linux/zutil.h>
7#include "infblock.h"
8#include "inftrees.h"
9#include "infcodes.h"
10#include "infutil.h"
11
12struct inflate_codes_state;
13
14/* And'ing with mask[n] masks the lower n bits */
15uInt zlib_inflate_mask[17] = {
16 0x0000,
17 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
18 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
19};
20
21
22/* copy as much as possible from the sliding window to the output area */
23int zlib_inflate_flush(
24 inflate_blocks_statef *s,
25 z_streamp z,
26 int r
27)
28{
29 uInt n;
30 Byte *p;
31 Byte *q;
32
33 /* local copies of source and destination pointers */
34 p = z->next_out;
35 q = s->read;
36
37 /* compute number of bytes to copy as far as end of window */
38 n = (uInt)((q <= s->write ? s->write : s->end) - q);
39 if (n > z->avail_out) n = z->avail_out;
40 if (n && r == Z_BUF_ERROR) r = Z_OK;
41
42 /* update counters */
43 z->avail_out -= n;
44 z->total_out += n;
45
46 /* update check information */
47 if (s->checkfn != NULL)
48 z->adler = s->check = (*s->checkfn)(s->check, q, n);
49
50 /* copy as far as end of window */
51 memcpy(p, q, n);
52 p += n;
53 q += n;
54
55 /* see if more to copy at beginning of window */
56 if (q == s->end)
57 {
58 /* wrap pointers */
59 q = s->window;
60 if (s->write == s->end)
61 s->write = s->window;
62
63 /* compute bytes to copy */
64 n = (uInt)(s->write - q);
65 if (n > z->avail_out) n = z->avail_out;
66 if (n && r == Z_BUF_ERROR) r = Z_OK;
67
68 /* update counters */
69 z->avail_out -= n;
70 z->total_out += n;
71
72 /* update check information */
73 if (s->checkfn != NULL)
74 z->adler = s->check = (*s->checkfn)(s->check, q, n);
75
76 /* copy */
77 memcpy(p, q, n);
78 p += n;
79 q += n;
80 }
81
82 /* update pointers */
83 z->next_out = p;
84 s->read = q;
85
86 /* done */
87 return r;
88}