Lines Matching refs:state
20 local int gz_load(state, buf, len, have) in gz_load() argument
21 gz_statep state; in gz_load()
30 ret = read(state->fd, buf + *have, len - *have);
36 gz_error(state, Z_ERRNO, zstrerror());
40 state->eof = 1;
51 local int gz_avail(state) in gz_avail() argument
52 gz_statep state; in gz_avail()
55 z_streamp strm = &(state->strm);
57 if (state->err != Z_OK && state->err != Z_BUF_ERROR)
59 if (state->eof == 0) {
61 unsigned char *p = state->in;
68 if (gz_load(state, state->in + strm->avail_in,
69 state->size - strm->avail_in, &got) == -1)
72 strm->next_in = state->in;
86 local int gz_look(state) in gz_look() argument
87 gz_statep state; in gz_look()
89 z_streamp strm = &(state->strm);
92 if (state->size == 0) {
94 state->in = (unsigned char *)malloc(state->want);
95 state->out = (unsigned char *)malloc(state->want << 1);
96 if (state->in == NULL || state->out == NULL) {
97 if (state->out != NULL)
98 free(state->out);
99 if (state->in != NULL)
100 free(state->in);
101 gz_error(state, Z_MEM_ERROR, "out of memory");
104 state->size = state->want;
107 state->strm.zalloc = Z_NULL;
108 state->strm.zfree = Z_NULL;
109 state->strm.opaque = Z_NULL;
110 state->strm.avail_in = 0;
111 state->strm.next_in = Z_NULL;
112 if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) { /* gunzip */
113 free(state->out);
114 free(state->in);
115 state->size = 0;
116 gz_error(state, Z_MEM_ERROR, "out of memory");
123 if (gz_avail(state) == -1)
139 state->how = GZIP;
140 state->direct = 0;
146 if (state->direct == 0) {
148 state->eof = 1;
149 state->x.have = 0;
156 state->x.next = state->out;
158 memcpy(state->x.next, strm->next_in, strm->avail_in);
159 state->x.have = strm->avail_in;
162 state->how = COPY;
163 state->direct = 1;
172 local int gz_decomp(state) in gz_decomp() argument
173 gz_statep state; in gz_decomp()
177 z_streamp strm = &(state->strm);
183 if (strm->avail_in == 0 && gz_avail(state) == -1)
186 gz_error(state, Z_BUF_ERROR, "unexpected end of file");
193 gz_error(state, Z_STREAM_ERROR,
198 gz_error(state, Z_MEM_ERROR, "out of memory");
202 gz_error(state, Z_DATA_ERROR,
209 state->x.have = had - strm->avail_out;
210 state->x.next = strm->next_out - state->x.have;
214 state->how = LOOK;
226 local int gz_fetch(state) in gz_fetch() argument
227 gz_statep state; in gz_fetch()
229 z_streamp strm = &(state->strm);
232 switch(state->how) {
234 if (gz_look(state) == -1)
236 if (state->how == LOOK)
240 if (gz_load(state, state->out, state->size << 1, &(state->x.have))
243 state->x.next = state->out;
246 strm->avail_out = state->size << 1;
247 strm->next_out = state->out;
248 if (gz_decomp(state) == -1)
251 } while (state->x.have == 0 && (!state->eof || strm->avail_in));
256 local int gz_skip(state, len) in gz_skip() argument
257 gz_statep state; in gz_skip()
265 if (state->x.have) {
266 n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ?
267 (unsigned)len : state->x.have;
268 state->x.have -= n;
269 state->x.next += n;
270 state->x.pos += n;
275 else if (state->eof && state->strm.avail_in == 0)
281 if (gz_fetch(state) == -1)
294 gz_statep state; local
300 state = (gz_statep)file;
301 strm = &(state->strm);
304 if (state->mode != GZ_READ ||
305 (state->err != Z_OK && state->err != Z_BUF_ERROR))
311 gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
320 if (state->seek) {
321 state->seek = 0;
322 if (gz_skip(state, state->skip) == -1)
330 if (state->x.have) {
331 n = state->x.have > len ? len : state->x.have;
332 memcpy(buf, state->x.next, n);
333 state->x.next += n;
334 state->x.have -= n;
338 else if (state->eof && strm->avail_in == 0) {
339 state->past = 1; /* tried to read past end */
345 else if (state->how == LOOK || len < (state->size << 1)) {
347 if (gz_fetch(state) == -1)
355 else if (state->how == COPY) { /* read directly */
356 if (gz_load(state, (unsigned char *)buf, len, &n) == -1)
364 if (gz_decomp(state) == -1)
366 n = state->x.have;
367 state->x.have = 0;
374 state->x.pos += n;
392 gz_statep state; local
397 state = (gz_statep)file;
400 if (state->mode != GZ_READ ||
401 (state->err != Z_OK && state->err != Z_BUF_ERROR))
405 if (state->x.have) {
406 state->x.have--;
407 state->x.pos++;
408 return *(state->x.next)++;
427 gz_statep state; local
432 state = (gz_statep)file;
435 if (state->mode != GZ_READ ||
436 (state->err != Z_OK && state->err != Z_BUF_ERROR))
440 if (state->seek) {
441 state->seek = 0;
442 if (gz_skip(state, state->skip) == -1)
451 if (state->x.have == 0) {
452 state->x.have = 1;
453 state->x.next = state->out + (state->size << 1) - 1;
454 state->x.next[0] = c;
455 state->x.pos--;
456 state->past = 0;
461 if (state->x.have == (state->size << 1)) {
462 gz_error(state, Z_DATA_ERROR, "out of room to push characters");
467 if (state->x.next == state->out) {
468 unsigned char *src = state->out + state->x.have;
469 unsigned char *dest = state->out + (state->size << 1);
470 while (src > state->out)
472 state->x.next = dest;
474 state->x.have++;
475 state->x.next--;
476 state->x.next[0] = c;
477 state->x.pos--;
478 state->past = 0;
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)
517 if (state->x.have == 0 && gz_fetch(state) == -1)
519 if (state->x.have == 0) { /* end of file */
520 state->past = 1; /* read past end */
525 n = state->x.have > left ? left : state->x.have;
526 eol = (unsigned char *)memchr(state->x.next, '\n', n);
528 n = (unsigned)(eol - state->x.next) + 1;
531 memcpy(buf, state->x.next, n);
532 state->x.have -= n;
533 state->x.next += n;
534 state->x.pos += n;
550 gz_statep state; local
555 state = (gz_statep)file;
559 if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
560 (void)gz_look(state);
563 return state->direct;
571 gz_statep state; local
576 state = (gz_statep)file;
579 if (state->mode != GZ_READ)
583 if (state->size) {
584 inflateEnd(&(state->strm));
585 free(state->out);
586 free(state->in);
588 err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
589 gz_error(state, Z_OK, NULL);
590 free(state->path);
591 ret = close(state->fd);
592 free(state);