28 unsigned get, max = ((unsigned)-1 >> 2) + 1;
35 ret = read(state->fd, buf + *have, get);
38 *have += (unsigned)ret;
39 }
while (*have < len);
64 if (state->eof == 0) {
66 unsigned char *p = state->in;
67 unsigned const char *q = strm->next_in;
68 unsigned n = strm->avail_in;
73 if (
gz_load(state, state->in + strm->avail_in,
74 state->size - strm->avail_in, &got) == -1)
76 strm->avail_in += got;
77 strm->next_in = state->in;
97 if (state->size == 0) {
99 state->in = (
unsigned char *)malloc(state->want);
100 state->out = (
unsigned char *)malloc(state->want << 1);
101 if (state->in == NULL || state->out == NULL) {
107 state->size = state->want;
110 state->strm.zalloc =
Z_NULL;
111 state->strm.zfree =
Z_NULL;
112 state->strm.opaque =
Z_NULL;
113 state->strm.avail_in = 0;
114 state->strm.next_in =
Z_NULL;
125 if (strm->avail_in < 2) {
128 if (strm->avail_in == 0)
139 if (strm->avail_in > 1 &&
140 strm->next_in[0] == 31 && strm->next_in[1] == 139) {
149 if (state->direct == 0) {
159 state->x.next = state->out;
160 memcpy(state->x.next, strm->next_in, strm->avail_in);
161 state->x.have = strm->avail_in;
181 had = strm->avail_out;
184 if (strm->avail_in == 0 &&
gz_avail(state) == -1)
186 if (strm->avail_in == 0) {
195 "internal error: inflate stream corrupt");
204 strm->msg == NULL ?
"compressed data error" : strm->msg);
210 state->x.have = had - strm->avail_out;
211 state->x.next = strm->next_out - state->x.have;
237 if (state->how ==
LOOK)
241 if (
gz_load(state, state->out, state->size << 1, &(state->x.have))
244 state->x.next = state->out;
247 strm->avail_out = state->size << 1;
248 strm->next_out = state->out;
252 }
while (state->x.have == 0 && (!state->eof || strm->avail_in));
267 n =
GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ?
268 (
unsigned)len : state->x.have;
276 else if (state->eof && state->strm.avail_in == 0)
307 if (
gz_skip(state, state->skip) == -1)
321 if (state->x.have < n)
323 memcpy(buf, state->x.next, n);
329 else if (state->eof && state->strm.avail_in == 0) {
336 else if (state->how ==
LOOK || n < (state->size << 1)) {
346 else if (state->how ==
COPY) {
347 if (
gz_load(state, (
unsigned char *)buf, n, &n) == -1)
353 state->strm.avail_out = n;
354 state->strm.next_out = (
unsigned char *)buf;
363 buf = (
char *)buf + n;
398 len = (unsigned)
gz_read(state, buf, len);
409z_size_t ZEXPORT
gzfread(buf, size, nitems, file)
430 if (size && len / size != nitems) {
436 return len ?
gz_read(state, buf, len) / size : 0;
448 unsigned char buf[1];
465 return *(state->x.next)++;
469 return gz_read(state, buf, 1) < 1 ? -1 : buf[0];
498 if (
gz_skip(state, state->skip) == -1)
507 if (state->x.have == 0) {
509 state->x.next = state->out + (state->size << 1) - 1;
510 state->x.next[0] = (
unsigned char)c;
517 if (state->x.have == (state->size << 1)) {
523 if (state->x.next == state->out) {
524 unsigned char *src = state->out + state->x.have;
525 unsigned char *dest = state->out + (state->size << 1);
526 while (src > state->out)
528 state->x.next = dest;
532 state->x.next[0] = (
unsigned char)c;
550 if (file == NULL || buf == NULL || len < 1)
562 if (
gz_skip(state, state->skip) == -1)
570 left = (unsigned)len - 1;
573 if (state->x.have == 0 &&
gz_fetch(state) == -1)
575 if (state->x.have == 0) {
581 n = state->x.have > left ? left : state->x.have;
582 eol = (
unsigned char *)memchr(state->x.next,
'\n', n);
584 n = (unsigned)(eol - state->x.next) + 1;
587 memcpy(buf, state->x.next, n);
593 }
while (left && eol == NULL);
615 if (state->mode ==
GZ_READ && state->how ==
LOOK && state->x.have == 0)
619 return state->direct;
647 ret = close(state->fd);
void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
int ZEXPORT gzungetc(int c, gzFile file)
int ZEXPORT gzdirect(gzFile file)
local int gz_fetch(gz_statep state)
local int gz_look(gz_statep state)
int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
local z_size_t gz_read(gz_statep state, voidp buf, z_size_t len)
int ZEXPORT gzgetc_(gzFile file)
local int gz_decomp(gz_statep state)
int ZEXPORT gzclose_r(gzFile file)
local int gz_avail(gz_statep state)
char *ZEXPORT gzgets(gzFile file, char *buf, int len)
local int gz_skip(gz_statep state, z_off64_t len)
z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, gzFile file)
local int gz_load(gz_statep state, unsigned char *buf, unsigned len, unsigned *have)
int ZEXPORT inflate(z_streamp strm, int flush)
int ZEXPORT inflateReset(z_streamp strm)
int ZEXPORT inflateEnd(z_streamp strm)
voidpf alloc_func OF((voidpf opaque, uInt items, uInt size))
#define inflateInit2(strm, windowBits)