1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/compressionlibs/ziplib/test/oldezlib/Zlib/infutil.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,84 @@
1.4 +/* inflate_util.c -- data and routines common to blocks and codes
1.5 + * Copyright (C) 1995-1998 Mark Adler
1.6 + * For conditions of distribution and use, see copyright notice in zlib.h
1.7 + */
1.8 +
1.9 +#include "zutil.h"
1.10 +#include "infblock.h"
1.11 +#include "inftrees.h"
1.12 +#include "infcodes.h"
1.13 +#include "infutil.h"
1.14 +
1.15 +struct inflate_codes_state {int dummy;}; /* for buggy compilers */
1.16 +
1.17 +/* And'ing with mask[n] masks the lower n bits */
1.18 +uInt inflate_mask[17] = {
1.19 + 0x0000,
1.20 + 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
1.21 + 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
1.22 +};
1.23 +
1.24 +
1.25 +/* copy as much as possible from the sliding window to the output area */
1.26 +int inflate_flush(inflate_blocks_statef *s, z_streamp z, int r)
1.27 +{
1.28 + uInt n;
1.29 + Bytef *p;
1.30 + Bytef *q;
1.31 +
1.32 + /* local copies of source and destination pointers */
1.33 + p = z->next_out;
1.34 + q = s->read;
1.35 +
1.36 + /* compute number of bytes to copy as far as end of window */
1.37 + n = (uInt)((q <= s->write ? s->write : s->end) - q);
1.38 + if (n > z->avail_out) n = z->avail_out;
1.39 + if (n && r == Z_BUF_ERROR) r = Z_OK;
1.40 +
1.41 + /* update counters */
1.42 + z->avail_out -= n;
1.43 + z->total_out += n;
1.44 +
1.45 + /* update check information */
1.46 + if (s->checkfn != Z_NULL)
1.47 + z->adler = s->check = (*s->checkfn)(s->check, q, n);
1.48 +
1.49 + /* copy as far as end of window */
1.50 + zmemcpy(p, q, n);
1.51 + p += n;
1.52 + q += n;
1.53 +
1.54 + /* see if more to copy at beginning of window */
1.55 + if (q == s->end)
1.56 + {
1.57 + /* wrap pointers */
1.58 + q = s->window;
1.59 + if (s->write == s->end)
1.60 + s->write = s->window;
1.61 +
1.62 + /* compute bytes to copy */
1.63 + n = (uInt)(s->write - q);
1.64 + if (n > z->avail_out) n = z->avail_out;
1.65 + if (n && r == Z_BUF_ERROR) r = Z_OK;
1.66 +
1.67 + /* update counters */
1.68 + z->avail_out -= n;
1.69 + z->total_out += n;
1.70 +
1.71 + /* update check information */
1.72 + if (s->checkfn != Z_NULL)
1.73 + z->adler = s->check = (*s->checkfn)(s->check, q, n);
1.74 +
1.75 + /* copy */
1.76 + zmemcpy(p, q, n);
1.77 + p += n;
1.78 + q += n;
1.79 + }
1.80 +
1.81 + /* update pointers */
1.82 + z->next_out = p;
1.83 + s->read = q;
1.84 +
1.85 + /* done */
1.86 + return r;
1.87 +}