30 ret =
read(state->fd, buf + *have, len - *have);
34 }
while (*have < len);
59 if (state->eof == 0) {
61 unsigned char *p = state->in, *q = strm->next_in;
62 unsigned n = strm->avail_in;
67 if (
gz_load(state, state->in + strm->avail_in,
68 state->size - strm->avail_in, &got) == -1)
70 strm->avail_in += got;
71 strm->next_in = state->in;
91 if (state->size == 0) {
93 state->in = malloc(state->want);
94 state->out = malloc(state->want << 1);
95 if (state->in == NULL || state->out == NULL) {
96 if (state->out != NULL)
98 if (state->in != NULL)
103 state->size = state->want;
106 state->strm.zalloc =
Z_NULL;
107 state->strm.zfree =
Z_NULL;
108 state->strm.opaque =
Z_NULL;
109 state->strm.avail_in = 0;
110 state->strm.next_in =
Z_NULL;
121 if (strm->avail_in < 2) {
124 if (strm->avail_in == 0)
135 if (strm->avail_in > 1 &&
136 strm->next_in[0] == 31 && strm->next_in[1] == 139) {
145 if (state->direct == 0) {
155 state->x.next = state->out;
156 if (strm->avail_in) {
157 memcpy(state->x.next, strm->next_in, strm->avail_in);
158 state->x.have = strm->avail_in;
179 had = strm->avail_out;
182 if (strm->avail_in == 0 &&
gz_avail(state) == -1)
184 if (strm->avail_in == 0) {
193 "internal error: inflate stream corrupt");
202 strm->msg == NULL ?
"compressed data error" : strm->msg);
208 state->x.have = had - strm->avail_out;
209 state->x.next = strm->next_out - state->x.have;
235 if (state->how ==
LOOK)
239 if (
gz_load(state, state->out, state->size << 1, &(state->x.have))
242 state->x.next = state->out;
245 strm->avail_out = state->size << 1;
246 strm->next_out = state->out;
250 }
while (state->x.have == 0 && (!state->eof || strm->avail_in));
266 (
unsigned)len : state->x.have;
274 else if (state->eof && state->strm.avail_in == 0)
300 strm = &(state->strm);
321 if (
gz_skip(state, state->skip) == -1)
330 n = state->x.have > len ? len : state->x.have;
331 memcpy(buf, state->x.next, n);
337 else if (state->eof && strm->avail_in == 0) {
344 else if (state->how ==
LOOK || len < (state->size << 1)) {
354 else if (state->how ==
COPY) {
355 if (
gz_load(state, buf, len, &n) == -1)
361 strm->avail_out = len;
362 strm->next_out = buf;
371 buf = (
char *)buf + n;
386 unsigned char buf[1];
403 return *(state->x.next)++;
407 ret =
gzread(file, buf, 1);
408 return ret < 1 ? -1 : buf[0];
437 if (
gz_skip(state, state->skip) == -1)
446 if (state->x.have == 0) {
448 state->x.next = state->out + (state->size << 1) - 1;
449 state->x.next[0] = c;
456 if (state->x.have == (state->size << 1)) {
462 if (state->x.next == state->out) {
463 unsigned char *src = state->out + state->x.have;
464 unsigned char *dest = state->out + (state->size << 1);
465 while (src > state->out)
467 state->x.next = dest;
471 state->x.next[0] = c;
489 if (file == NULL || buf == NULL || len < 1)
501 if (
gz_skip(state, state->skip) == -1)
509 left = (unsigned)len - 1;
512 if (state->x.have == 0 &&
gz_fetch(state) == -1)
514 if (state->x.have == 0) {
520 n = state->x.have > left ? left : state->x.have;
521 eol = memchr(state->x.next,
'\n', n);
523 n = (unsigned)(eol - state->x.next) + 1;
526 memcpy(buf, state->x.next, n);
532 }
while (left && eol == NULL);
554 if (state->mode ==
GZ_READ && state->how ==
LOOK && state->x.have == 0)
558 return state->direct;
586 ret = close(state->fd);