Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / lib / libz / infutil.c
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  * $FreeBSD: src/lib/libz/infutil.c,v 1.1.1.2.6.1 2003/02/01 13:33:12 sobomax Exp $
6  * $DragonFly: src/lib/libz/Attic/infutil.c,v 1.2 2003/06/17 04:26:52 dillon Exp $
7  */
8
9 #include "zutil.h"
10 #include "infblock.h"
11 #include "inftrees.h"
12 #include "infcodes.h"
13 #include "infutil.h"
14
15 struct inflate_codes_state {int dummy;}; /* for buggy compilers */
16
17 /* And'ing with mask[n] masks the lower n bits */
18 uInt inflate_mask[17] = {
19     0x0000,
20     0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
21     0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
22 };
23
24
25 /* copy as much as possible from the sliding window to the output area */
26 int inflate_flush(s, z, r)
27 inflate_blocks_statef *s;
28 z_streamp z;
29 int r;
30 {
31   uInt n;
32   Bytef *p;
33   Bytef *q;
34
35   /* local copies of source and destination pointers */
36   p = z->next_out;
37   q = s->read;
38
39   /* compute number of bytes to copy as far as end of window */
40   n = (uInt)((q <= s->write ? s->write : s->end) - q);
41   if (n > z->avail_out) n = z->avail_out;
42   if (n && r == Z_BUF_ERROR) r = Z_OK;
43
44   /* update counters */
45   z->avail_out -= n;
46   z->total_out += n;
47
48   /* update check information */
49   if (s->checkfn != Z_NULL)
50     z->adler = s->check = (*s->checkfn)(s->check, q, n);
51
52   /* copy as far as end of window */
53   zmemcpy(p, q, n);
54   p += n;
55   q += n;
56
57   /* see if more to copy at beginning of window */
58   if (q == s->end)
59   {
60     /* wrap pointers */
61     q = s->window;
62     if (s->write == s->end)
63       s->write = s->window;
64
65     /* compute bytes to copy */
66     n = (uInt)(s->write - q);
67     if (n > z->avail_out) n = z->avail_out;
68     if (n && r == Z_BUF_ERROR) r = Z_OK;
69
70     /* update counters */
71     z->avail_out -= n;
72     z->total_out += n;
73
74     /* update check information */
75     if (s->checkfn != Z_NULL)
76       z->adler = s->check = (*s->checkfn)(s->check, q, n);
77
78     /* copy */
79     zmemcpy(p, q, n);
80     p += n;
81     q += n;
82   }
83
84   /* update pointers */
85   z->next_out = p;
86   s->read = q;
87
88   /* done */
89   return r;
90 }