]> git.saurik.com Git - apple/security.git/blob - SecurityServer/MacYarrow/zlib/infutil.c
Security-28.tar.gz
[apple/security.git] / SecurityServer / MacYarrow / zlib / infutil.c
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 /* inflate_util.c -- data and routines common to blocks and codes
20 * Copyright (C) 1995-1998 Mark Adler
21 * For conditions of distribution and use, see copyright notice in zlib.h
22 */
23
24 #include "zutil.h"
25 #include "infblock.h"
26 #include "inftrees.h"
27 #include "infcodes.h"
28 #include "infutil.h"
29
30 struct inflate_codes_state {int dummy;}; /* for buggy compilers */
31
32 /* And'ing with mask[n] masks the lower n bits */
33 uInt inflate_mask[17] = {
34 0x0000,
35 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
36 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
37 };
38
39
40 /* copy as much as possible from the sliding window to the output area */
41 int inflate_flush(s, z, r)
42 inflate_blocks_statef *s;
43 z_streamp z;
44 int r;
45 {
46 uInt n;
47 Bytef *p;
48 Bytef *q;
49
50 /* local copies of source and destination pointers */
51 p = z->next_out;
52 q = s->read;
53
54 /* compute number of bytes to copy as far as end of window */
55 n = (uInt)((q <= s->write ? s->write : s->end) - 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 if (s->checkfn != Z_NULL)
65 z->adler = s->check = (*s->checkfn)(s->check, q, n);
66
67 /* copy as far as end of window */
68 zmemcpy(p, q, n);
69 p += n;
70 q += n;
71
72 /* see if more to copy at beginning of window */
73 if (q == s->end)
74 {
75 /* wrap pointers */
76 q = s->window;
77 if (s->write == s->end)
78 s->write = s->window;
79
80 /* compute bytes to copy */
81 n = (uInt)(s->write - q);
82 if (n > z->avail_out) n = z->avail_out;
83 if (n && r == Z_BUF_ERROR) r = Z_OK;
84
85 /* update counters */
86 z->avail_out -= n;
87 z->total_out += n;
88
89 /* update check information */
90 if (s->checkfn != Z_NULL)
91 z->adler = s->check = (*s->checkfn)(s->check, q, n);
92
93 /* copy */
94 zmemcpy(p, q, n);
95 p += n;
96 q += n;
97 }
98
99 /* update pointers */
100 z->next_out = p;
101 s->read = q;
102
103 /* done */
104 return r;
105 }