00001
00002
00003
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;};
00013
00014
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
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
00033 p = z->next_out;
00034 q = s->read;
00035
00036
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
00042 z->avail_out -= n;
00043 z->total_out += n;
00044
00045
00046 if (s->checkfn != Z_NULL)
00047 z->adler = s->check = (*s->checkfn)(s->check, q, n);
00048
00049
00050 zmemcpy(p, q, n);
00051 p += n;
00052 q += n;
00053
00054
00055 if (q == s->end)
00056 {
00057
00058 q = s->window;
00059 if (s->write == s->end)
00060 s->write = s->window;
00061
00062
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
00068 z->avail_out -= n;
00069 z->total_out += n;
00070
00071
00072 if (s->checkfn != Z_NULL)
00073 z->adler = s->check = (*s->checkfn)(s->check, q, n);
00074
00075
00076 zmemcpy(p, q, n);
00077 p += n;
00078 q += n;
00079 }
00080
00081
00082 z->next_out = p;
00083 s->read = q;
00084
00085
00086 return r;
00087 }