]> git.saurik.com Git - wxWidgets.git/blame - src/zlib/infutil.c
made wxFFile a bit more safe: don't crash when Tell() and Length() are called on...
[wxWidgets.git] / src / zlib / infutil.c
CommitLineData
c801d85f 1/* inflate_util.c -- data and routines common to blocks and codes
a4019ec2 2 * Copyright (C) 1995-2002 Mark Adler
e6ebb514 3 * For conditions of distribution and use, see copyright notice in zlib.h
c801d85f
KB
4 */
5
6#include "zutil.h"
7#include "infblock.h"
8#include "inftrees.h"
9#include "infcodes.h"
10#include "infutil.h"
11
12struct inflate_codes_state {int dummy;}; /* for buggy compilers */
13
14/* And'ing with mask[n] masks the lower n bits */
15uInt 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 */
75bce3ad 23#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */
e6ebb514
DW
24int inflate_flush(inflate_blocks_statef* s, z_streamp z, int r)
25#else
c801d85f
KB
26int inflate_flush(s, z, r)
27inflate_blocks_statef *s;
28z_streamp z;
29int r;
e6ebb514 30#endif
c801d85f
KB
31{
32 uInt n;
33 Bytef *p;
34 Bytef *q;
35
36 /* local copies of source and destination pointers */
37 p = z->next_out;
38 q = s->read;
39
40 /* compute number of bytes to copy as far as end of window */
41 n = (uInt)((q <= s->write ? s->write : s->end) - q);
42 if (n > z->avail_out) n = z->avail_out;
43 if (n && r == Z_BUF_ERROR) r = Z_OK;
44
45 /* update counters */
46 z->avail_out -= n;
47 z->total_out += n;
48
49 /* update check information */
50 if (s->checkfn != Z_NULL)
51 z->adler = s->check = (*s->checkfn)(s->check, q, n);
52
53 /* copy as far as end of window */
54 zmemcpy(p, q, n);
55 p += n;
56 q += n;
57
58 /* see if more to copy at beginning of window */
59 if (q == s->end)
60 {
61 /* wrap pointers */
62 q = s->window;
63 if (s->write == s->end)
64 s->write = s->window;
65
66 /* compute bytes to copy */
67 n = (uInt)(s->write - q);
68 if (n > z->avail_out) n = z->avail_out;
69 if (n && r == Z_BUF_ERROR) r = Z_OK;
70
71 /* update counters */
72 z->avail_out -= n;
73 z->total_out += n;
74
75 /* update check information */
76 if (s->checkfn != Z_NULL)
77 z->adler = s->check = (*s->checkfn)(s->check, q, n);
78
79 /* copy */
80 zmemcpy(p, q, n);
81 p += n;
82 q += n;
83 }
84
85 /* update pointers */
86 z->next_out = p;
87 s->read = q;
88
89 /* done */
90 return r;
91}