Lines Matching refs:state
21 local int gz_load(state, buf, len, have) in gz_load() argument
22 gz_statep state; in gz_load()
35 ret = read(state->fd, buf + *have, get);
41 gz_error(state, Z_ERRNO, zstrerror());
45 state->eof = 1;
56 local int gz_avail(state) in gz_avail() argument
57 gz_statep state; in gz_avail()
60 z_streamp strm = &(state->strm);
62 if (state->err != Z_OK && state->err != Z_BUF_ERROR)
64 if (state->eof == 0) {
66 unsigned char *p = state->in;
73 if (gz_load(state, state->in + strm->avail_in,
74 state->size - strm->avail_in, &got) == -1)
77 strm->next_in = state->in;
91 local int gz_look(state) in gz_look() argument
92 gz_statep state; in gz_look()
94 z_streamp strm = &(state->strm);
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) {
102 free(state->out);
103 free(state->in);
104 gz_error(state, Z_MEM_ERROR, "out of memory");
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;
115 if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) { /* gunzip */
116 free(state->out);
117 free(state->in);
118 state->size = 0;
119 gz_error(state, Z_MEM_ERROR, "out of memory");
126 if (gz_avail(state) == -1)
142 state->how = GZIP;
143 state->direct = 0;
149 if (state->direct == 0) {
151 state->eof = 1;
152 state->x.have = 0;
159 state->x.next = state->out;
161 memcpy(state->x.next, strm->next_in, strm->avail_in);
162 state->x.have = strm->avail_in;
165 state->how = COPY;
166 state->direct = 1;
175 local int gz_decomp(state) in gz_decomp() argument
176 gz_statep state; in gz_decomp()
180 z_streamp strm = &(state->strm);
186 if (strm->avail_in == 0 && gz_avail(state) == -1)
189 gz_error(state, Z_BUF_ERROR, "unexpected end of file");
196 gz_error(state, Z_STREAM_ERROR,
201 gz_error(state, Z_MEM_ERROR, "out of memory");
205 gz_error(state, Z_DATA_ERROR,
212 state->x.have = had - strm->avail_out;
213 state->x.next = strm->next_out - state->x.have;
217 state->how = LOOK;
229 local int gz_fetch(state) in gz_fetch() argument
230 gz_statep state; in gz_fetch()
232 z_streamp strm = &(state->strm);
235 switch(state->how) {
237 if (gz_look(state) == -1)
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;
251 if (gz_decomp(state) == -1)
254 } while (state->x.have == 0 && (!state->eof || strm->avail_in));
259 local int gz_skip(state, len) in gz_skip() argument
260 gz_statep state; in gz_skip()
268 if (state->x.have) {
269 n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ?
270 (unsigned)len : state->x.have;
271 state->x.have -= n;
272 state->x.next += n;
273 state->x.pos += n;
278 else if (state->eof && state->strm.avail_in == 0)
284 if (gz_fetch(state) == -1)
294 local z_size_t gz_read(state, buf, len) in gz_read() argument
295 gz_statep state; in gz_read()
307 if (state->seek) {
308 state->seek = 0;
309 if (gz_skip(state, state->skip) == -1)
322 if (state->x.have) {
323 if (state->x.have < n)
324 n = state->x.have;
325 memcpy(buf, state->x.next, n);
326 state->x.next += n;
327 state->x.have -= n;
331 else if (state->eof && state->strm.avail_in == 0) {
332 state->past = 1; /* tried to read past end */
338 else if (state->how == LOOK || n < (state->size << 1)) {
340 if (gz_fetch(state) == -1)
348 else if (state->how == COPY) { /* read directly */
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;
357 if (gz_decomp(state) == -1)
359 n = state->x.have;
360 state->x.have = 0;
367 state->x.pos += n;
380 gz_statep state; local
385 state = (gz_statep)file;
388 if (state->mode != GZ_READ ||
389 (state->err != Z_OK && state->err != Z_BUF_ERROR))
395 gz_error(state, Z_STREAM_ERROR, "request does not fit in an int");
400 len = gz_read(state, buf, len);
403 if (len == 0 && state->err != Z_OK && state->err != Z_BUF_ERROR)
418 gz_statep state; local
423 state = (gz_statep)file;
426 if (state->mode != GZ_READ ||
427 (state->err != Z_OK && state->err != Z_BUF_ERROR))
433 gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
438 return len ? gz_read(state, buf, len) / size : 0;
456 gz_statep state; local
461 state = (gz_statep)file;
464 if (state->mode != GZ_READ ||
465 (state->err != Z_OK && state->err != Z_BUF_ERROR))
469 if (state->x.have) {
470 state->x.have--;
471 state->x.pos++;
472 return *(state->x.next)++;
476 ret = gz_read(state, buf, 1);
491 gz_statep state; local
496 state = (gz_statep)file;
499 if (state->mode != GZ_READ ||
500 (state->err != Z_OK && state->err != Z_BUF_ERROR))
504 if (state->seek) {
505 state->seek = 0;
506 if (gz_skip(state, state->skip) == -1)
515 if (state->x.have == 0) {
516 state->x.have = 1;
517 state->x.next = state->out + (state->size << 1) - 1;
518 state->x.next[0] = (unsigned char)c;
519 state->x.pos--;
520 state->past = 0;
525 if (state->x.have == (state->size << 1)) {
526 gz_error(state, Z_DATA_ERROR, "out of room to push characters");
531 if (state->x.next == state->out) {
532 unsigned char *src = state->out + state->x.have;
533 unsigned char *dest = state->out + (state->size << 1);
534 while (src > state->out)
536 state->x.next = dest;
538 state->x.have++;
539 state->x.next--;
540 state->x.next[0] = (unsigned char)c;
541 state->x.pos--;
542 state->past = 0;
555 gz_statep state; local
560 state = (gz_statep)file;
563 if (state->mode != GZ_READ ||
564 (state->err != Z_OK && state->err != Z_BUF_ERROR))
568 if (state->seek) {
569 state->seek = 0;
570 if (gz_skip(state, state->skip) == -1)
581 if (state->x.have == 0 && gz_fetch(state) == -1)
583 if (state->x.have == 0) { /* end of file */
584 state->past = 1; /* read past end */
589 n = state->x.have > left ? left : state->x.have;
590 eol = (unsigned char *)memchr(state->x.next, '\n', n);
592 n = (unsigned)(eol - state->x.next) + 1;
595 memcpy(buf, state->x.next, n);
596 state->x.have -= n;
597 state->x.next += n;
598 state->x.pos += n;
614 gz_statep state; local
619 state = (gz_statep)file;
623 if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
624 (void)gz_look(state);
627 return state->direct;
635 gz_statep state; local
640 state = (gz_statep)file;
643 if (state->mode != GZ_READ)
647 if (state->size) {
648 inflateEnd(&(state->strm));
649 free(state->out);
650 free(state->in);
652 err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
653 gz_error(state, Z_OK, NULL);
654 free(state->path);
655 ret = close(state->fd);
656 free(state);