- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# infutil.c

    00001 /* inflate_util.c -- data and routines common to blocks and codes
    00002  * Copyright (C) 1995-2002 Mark Adler
    00003  * For conditions of distribution and use, see copyright notice in zlib.h
    00004  */
    00005
    00006 #include "zutil.h"
    00007 #include "infblock.h"
    00008 #include "inftrees.h"
    00009 #include "infcodes.h"
    00010 #include "infutil.h"
    00011
    00012 struct inflate_codes_state {int dummy;}; /* for buggy compilers */
    00013
    00014 /* And'ing with mask[n] masks the lower n bits */
    00015 uInt inflate_mask[17] = {
    00016     0x0000,
    00017     0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
    00018     0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
    00019 };
    00020
    00021
    00022 /* copy as much as possible from the sliding window to the output area */
    00023 int inflate_flush(s, z, r)
    00024 inflate_blocks_statef *s;
    00025 z_streamp z;
    00026 int r;
    00027 {
    00028   uInt n;
    00029   Bytef *p;
    00030   Bytef *q;
    00031
    00032   /* local copies of source and destination pointers */
    00033   p = z->next_out;
    00034   q = s->read;
    00035
    00036   /* compute number of bytes to copy as far as end of window */
    00037   n = (uInt)((q <= s->write ? s->write : s->end) - q);
    00038   if (n > z->avail_out) n = z->avail_out;
    00039   if (n && r == Z_BUF_ERROR) r = Z_OK;
    00040
    00041   /* update counters */
    00042   z->avail_out -= n;
    00043   z->total_out += n;
    00044
    00045   /* update check information */
    00046   if (s->checkfn != Z_NULL)
    00047     z->adler = s->check = (*s->checkfn)(s->check, q, n);
    00048
    00049   /* copy as far as end of window */
    00050   zmemcpy(p, q, n);
    00051   p += n;
    00052   q += n;
    00053
    00054   /* see if more to copy at beginning of window */
    00055   if (q == s->end)
    00056   {
    00057     /* wrap pointers */
    00058     q = s->window;
    00059     if (s->write == s->end)
    00060       s->write = s->window;
    00061
    00062     /* compute bytes to copy */
    00063     n = (uInt)(s->write - q);
    00064     if (n > z->avail_out) n = z->avail_out;
    00065     if (n && r == Z_BUF_ERROR) r = Z_OK;
    00066
    00067     /* update counters */
    00068     z->avail_out -= n;
    00069     z->total_out += n;
    00070
    00071     /* update check information */
    00072     if (s->checkfn != Z_NULL)
    00073       z->adler = s->check = (*s->checkfn)(s->check, q, n);
    00074
    00075     /* copy */
    00076     zmemcpy(p, q, n);
    00077     p += n;
    00078     q += n;
    00079   }
    00080
    00081   /* update pointers */
    00082   z->next_out = p;
    00083   s->read = q;
    00084
    00085   /* done */
    00086   return r;
    00087 }