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 if (strm->avail_in) {
161 memcpy(state->x.next, strm->next_in, strm->avail_in);
162 state->x.have = strm->avail_in;
183 had = strm->avail_out;
186 if (strm->avail_in == 0 &&
gz_avail(state) == -1)
188 if (strm->avail_in == 0) {
197 "internal error: inflate stream corrupt");
206 strm->msg == NULL ?
"compressed data error" : strm->msg);
212 state->x.have = had - strm->avail_out;
213 state->x.next = strm->next_out - state->x.have;
239 if (state->how ==
LOOK)
243 if (
gz_load(state, state->out, state->size << 1, &(state->x.have))
246 state->x.next = state->out;
249 strm->avail_out = state->size << 1;
250 strm->next_out = state->out;
254 }
while (state->x.have == 0 && (!state->eof || strm->avail_in));
269 n =
GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ?
270 (
unsigned)len : state->x.have;
278 else if (state->eof && state->strm.avail_in == 0)
309 if (
gz_skip(state, state->skip) == -1)
323 if (state->x.have < n)
325 memcpy(buf, state->x.next, n);
331 else if (state->eof && state->strm.avail_in == 0) {
338 else if (state->how ==
LOOK || n < (state->size << 1)) {
348 else if (state->how ==
COPY) {
349 if (
gz_load(state, (
unsigned char *)buf, n, &n) == -1)
355 state->strm.avail_out = n;
356 state->strm.next_out = (
unsigned char *)buf;
365 buf = (
char *)buf + n;
400 len = (unsigned)
gz_read(state, buf, len);
411z_size_t ZEXPORT
gzfread(buf, size, nitems, file)
432 if (size && len / size != nitems) {
438 return len ?
gz_read(state, buf, len) / size : 0;
451 unsigned char buf[1];
468 return *(state->x.next)++;
472 ret = (int)
gz_read(state, buf, 1);
473 return ret < 1 ? -1 : buf[0];
502 if (
gz_skip(state, state->skip) == -1)
511 if (state->x.have == 0) {
513 state->x.next = state->out + (state->size << 1) - 1;
514 state->x.next[0] = (
unsigned char)c;
521 if (state->x.have == (state->size << 1)) {
527 if (state->x.next == state->out) {
528 unsigned char *src = state->out + state->x.have;
529 unsigned char *dest = state->out + (state->size << 1);
530 while (src > state->out)
532 state->x.next = dest;
536 state->x.next[0] = (
unsigned char)c;
554 if (file == NULL || buf == NULL || len < 1)
566 if (
gz_skip(state, state->skip) == -1)
574 left = (unsigned)len - 1;
577 if (state->x.have == 0 &&
gz_fetch(state) == -1)
579 if (state->x.have == 0) {
585 n = state->x.have > left ? left : state->x.have;
586 eol = (
unsigned char *)memchr(state->x.next,
'\n', n);
588 n = (unsigned)(eol - state->x.next) + 1;
591 memcpy(buf, state->x.next, n);
597 }
while (left && eol == NULL);
619 if (state->mode ==
GZ_READ && state->how ==
LOOK && state->x.have == 0)
623 return state->direct;
651 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)
int gz_skip(gz_statep state, z_off64_t len)
int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
int ZEXPORT gzgetc_(gzFile file)
int gz_fetch(gz_statep state)
z_size_t gz_read(gz_statep state, voidp buf, z_size_t len)
int gz_decomp(gz_statep state)
int gz_avail(gz_statep state)
int ZEXPORT gzclose_r(gzFile file)
char *ZEXPORT gzgets(gzFile file, char *buf, int len)
int gz_load(gz_statep state, unsigned char *buf, unsigned len, unsigned *have)
int gz_look(gz_statep state)
z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, gzFile file)
int ZEXPORT inflate(z_streamp strm, int flush)
int ZEXPORT inflateReset(z_streamp strm)
int ZEXPORT inflateEnd(z_streamp strm)
#define inflateInit2(strm, windowBits)
voidpf alloc_func OF((voidpf opaque, uInt items, uInt size))