diff options
Diffstat (limited to '')
| -rw-r--r-- | infutil.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/infutil.c b/infutil.c new file mode 100644 index 0000000..92d115f --- /dev/null +++ b/infutil.c | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | /* inflate_util.c -- data and routines common to blocks and codes | ||
| 2 | * Copyright (C) 1995 Mark Adler | ||
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include "zutil.h" | ||
| 7 | #include "inftrees.h" | ||
| 8 | #include "infutil.h" | ||
| 9 | |||
| 10 | struct inflate_codes_state {int dummy;}; /* for buggy compilers */ | ||
| 11 | |||
| 12 | /* And'ing with mask[n] masks the lower n bits */ | ||
| 13 | uInt inflate_mask[] = { | ||
| 14 | 0x0000, | ||
| 15 | 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, | ||
| 16 | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff | ||
| 17 | }; | ||
| 18 | |||
| 19 | |||
| 20 | /* copy as much as possible from the sliding window to the output area */ | ||
| 21 | int inflate_flush(s, z, r) | ||
| 22 | struct inflate_blocks_state *s; | ||
| 23 | z_stream *z; | ||
| 24 | int r; | ||
| 25 | { | ||
| 26 | uInt n; | ||
| 27 | Byte *p, *q; | ||
| 28 | |||
| 29 | /* local copies of source and destination pointers */ | ||
| 30 | p = z->next_out; | ||
| 31 | q = s->read; | ||
| 32 | |||
| 33 | /* compute number of bytes to copy as far as end of window */ | ||
| 34 | n = (q <= s->write ? s->write : s->end) - q; | ||
| 35 | if (n > z->avail_out) n = z->avail_out; | ||
| 36 | if (n && r == Z_BUF_ERROR) r = Z_OK; | ||
| 37 | |||
| 38 | /* update counters */ | ||
| 39 | z->avail_out -= n; | ||
| 40 | z->total_out += n; | ||
| 41 | |||
| 42 | /* update check information */ | ||
| 43 | s->check = adler32(s->check, q, n); | ||
| 44 | |||
| 45 | /* copy as far as end of window */ | ||
| 46 | while (n--) *p++ = *q++; | ||
| 47 | |||
| 48 | /* see if more to copy at beginning of window */ | ||
| 49 | if (q == s->end) | ||
| 50 | { | ||
| 51 | /* wrap source pointer */ | ||
| 52 | q = s->window; | ||
| 53 | |||
| 54 | /* compute bytes to copy */ | ||
| 55 | n = s->write - q; | ||
| 56 | if (n > z->avail_out) n = z->avail_out; | ||
| 57 | if (n && r == Z_BUF_ERROR) r = Z_OK; | ||
| 58 | |||
| 59 | /* update counters */ | ||
| 60 | z->avail_out -= n; | ||
| 61 | z->total_out += n; | ||
| 62 | |||
| 63 | /* update check information */ | ||
| 64 | s->check = adler32(s->check, q, n); | ||
| 65 | |||
| 66 | /* copy */ | ||
| 67 | while (n--) *p++ = *q++; | ||
| 68 | } | ||
| 69 | |||
| 70 | /* update pointers */ | ||
| 71 | z->next_out = p; | ||
| 72 | s->read = q; | ||
| 73 | |||
| 74 | /* done */ | ||
| 75 | return r; | ||
| 76 | } | ||
