• Home
  • Raw
  • Download

Lines Matching full:state

17    state->fd, and update state->eof, state->err, and state->msg as appropriate.
21 gz_statep state, in gz_load() argument
30 ret = read(state->fd, buf + *have, len - *have); in gz_load()
36 gz_error(state, Z_ERRNO, zstrerror()); in gz_load()
40 state->eof = 1; in gz_load()
52 gz_statep state) in gz_avail() argument
55 z_streamp strm = &(state->strm); in gz_avail()
57 if (state->err != Z_OK && state->err != Z_BUF_ERROR) in gz_avail()
59 if (state->eof == 0) { in gz_avail()
61 unsigned char *p = state->in; in gz_avail()
68 if (gz_load(state, state->in + strm->avail_in, in gz_avail()
69 state->size - strm->avail_in, &got) == -1) in gz_avail()
72 strm->next_in = state->in; in gz_avail()
77 /* Look for gzip header, set up for inflate or copy. state->x.have must be 0.
78 If this is the first time in, allocate required memory. state->how will be
84 a user buffer. If decompressing, the inflate state will be initialized.
87 gz_statep state) in gz_look() argument
89 z_streamp strm = &(state->strm); in gz_look()
92 if (state->size == 0) { in gz_look()
94 state->in = (unsigned char *)malloc(state->want); in gz_look()
95 state->out = (unsigned char *)malloc(state->want << 1); in gz_look()
96 if (state->in == NULL || state->out == NULL) { in gz_look()
97 if (state->out != NULL) in gz_look()
98 free(state->out); in gz_look()
99 if (state->in != NULL) in gz_look()
100 free(state->in); in gz_look()
101 gz_error(state, Z_MEM_ERROR, "out of memory"); in gz_look()
104 state->size = state->want; in gz_look()
107 state->strm.zalloc = Z_NULL; in gz_look()
108 state->strm.zfree = Z_NULL; in gz_look()
109 state->strm.opaque = Z_NULL; in gz_look()
110 state->strm.avail_in = 0; in gz_look()
111 state->strm.next_in = Z_NULL; in gz_look()
112 if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) { /* gunzip */ in gz_look()
113 free(state->out); in gz_look()
114 free(state->in); in gz_look()
115 state->size = 0; in gz_look()
116 gz_error(state, Z_MEM_ERROR, "out of memory"); in gz_look()
123 if (gz_avail(state) == -1) in gz_look()
139 state->how = GZIP; in gz_look()
140 state->direct = 0; in gz_look()
146 if (state->direct == 0) { in gz_look()
148 state->eof = 1; in gz_look()
149 state->x.have = 0; in gz_look()
156 state->x.next = state->out; in gz_look()
158 memcpy(state->x.next, strm->next_in, strm->avail_in); in gz_look()
159 state->x.have = strm->avail_in; in gz_look()
162 state->how = COPY; in gz_look()
163 state->direct = 1; in gz_look()
167 /* Decompress from input to the provided next_out and avail_out in the state.
168 On return, state->x.have and state->x.next point to the just decompressed
169 data. If the gzip stream completes, state->how is reset to LOOK to look for
170 the next gzip stream or raw data, once state->x.have is depleted. Returns 0
173 gz_statep state) in gz_decomp() argument
177 z_streamp strm = &(state->strm); in gz_decomp()
183 if (strm->avail_in == 0 && gz_avail(state) == -1) in gz_decomp()
186 gz_error(state, Z_BUF_ERROR, "unexpected end of file"); in gz_decomp()
193 gz_error(state, Z_STREAM_ERROR, in gz_decomp()
198 gz_error(state, Z_MEM_ERROR, "out of memory"); in gz_decomp()
202 gz_error(state, Z_DATA_ERROR, in gz_decomp()
209 state->x.have = had - strm->avail_out; in gz_decomp()
210 state->x.next = strm->next_out - state->x.have; in gz_decomp()
214 state->how = LOOK; in gz_decomp()
220 /* Fetch data and put it in the output buffer. Assumes state->x.have is 0.
222 file depending on state->how. If state->how is LOOK, then a gzip header is
224 otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the
227 gz_statep state) in gz_fetch() argument
229 z_streamp strm = &(state->strm); in gz_fetch()
232 switch(state->how) { in gz_fetch()
234 if (gz_look(state) == -1) in gz_fetch()
236 if (state->how == LOOK) in gz_fetch()
240 if (gz_load(state, state->out, state->size << 1, &(state->x.have)) in gz_fetch()
243 state->x.next = state->out; in gz_fetch()
246 strm->avail_out = state->size << 1; in gz_fetch()
247 strm->next_out = state->out; in gz_fetch()
248 if (gz_decomp(state) == -1) in gz_fetch()
251 } while (state->x.have == 0 && (!state->eof || strm->avail_in)); in gz_fetch()
257 gz_statep state, in gz_skip() argument
265 if (state->x.have) { in gz_skip()
266 n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ? in gz_skip()
267 (unsigned)len : state->x.have; in gz_skip()
268 state->x.have -= n; in gz_skip()
269 state->x.next += n; in gz_skip()
270 state->x.pos += n; in gz_skip()
275 else if (state->eof && state->strm.avail_in == 0) in gz_skip()
281 if (gz_fetch(state) == -1) in gz_skip()
294 gz_statep state; in gzread() local
300 state = (gz_statep)file; in gzread()
301 strm = &(state->strm); in gzread()
304 if (state->mode != GZ_READ || in gzread()
305 (state->err != Z_OK && state->err != Z_BUF_ERROR)) in gzread()
311 gz_error(state, Z_DATA_ERROR, "requested length does not fit in int"); in gzread()
320 if (state->seek) { in gzread()
321 state->seek = 0; in gzread()
322 if (gz_skip(state, state->skip) == -1) in gzread()
330 if (state->x.have) { in gzread()
331 n = state->x.have > len ? len : state->x.have; in gzread()
332 memcpy(buf, state->x.next, n); in gzread()
333 state->x.next += n; in gzread()
334 state->x.have -= n; in gzread()
338 else if (state->eof && strm->avail_in == 0) { in gzread()
339 state->past = 1; /* tried to read past end */ in gzread()
345 else if (state->how == LOOK || len < (state->size << 1)) { in gzread()
347 if (gz_fetch(state) == -1) in gzread()
355 else if (state->how == COPY) { /* read directly */ in gzread()
356 if (gz_load(state, (unsigned char *)buf, len, &n) == -1) in gzread()
361 else { /* state->how == GZIP */ in gzread()
364 if (gz_decomp(state) == -1) in gzread()
366 n = state->x.have; in gzread()
367 state->x.have = 0; in gzread()
374 state->x.pos += n; in gzread()
392 gz_statep state; in gzgetc() local
397 state = (gz_statep)file; in gzgetc()
400 if (state->mode != GZ_READ || in gzgetc()
401 (state->err != Z_OK && state->err != Z_BUF_ERROR)) in gzgetc()
405 if (state->x.have) { in gzgetc()
406 state->x.have--; in gzgetc()
407 state->x.pos++; in gzgetc()
408 return *(state->x.next)++; in gzgetc()
427 gz_statep state; in gzungetc() local
432 state = (gz_statep)file; in gzungetc()
435 if (state->mode != GZ_READ || in gzungetc()
436 (state->err != Z_OK && state->err != Z_BUF_ERROR)) in gzungetc()
440 if (state->seek) { in gzungetc()
441 state->seek = 0; in gzungetc()
442 if (gz_skip(state, state->skip) == -1) in gzungetc()
451 if (state->x.have == 0) { in gzungetc()
452 state->x.have = 1; in gzungetc()
453 state->x.next = state->out + (state->size << 1) - 1; in gzungetc()
454 state->x.next[0] = c; in gzungetc()
455 state->x.pos--; in gzungetc()
456 state->past = 0; in gzungetc()
461 if (state->x.have == (state->size << 1)) { in gzungetc()
462 gz_error(state, Z_DATA_ERROR, "out of room to push characters"); in gzungetc()
467 if (state->x.next == state->out) { in gzungetc()
468 unsigned char *src = state->out + state->x.have; in gzungetc()
469 unsigned char *dest = state->out + (state->size << 1); in gzungetc()
470 while (src > state->out) in gzungetc()
472 state->x.next = dest; in gzungetc()
474 state->x.have++; in gzungetc()
475 state->x.next--; in gzungetc()
476 state->x.next[0] = c; in gzungetc()
477 state->x.pos--; in gzungetc()
478 state->past = 0; in gzungetc()
491 gz_statep state; in gzgets() local
496 state = (gz_statep)file; in gzgets()
499 if (state->mode != GZ_READ || in gzgets()
500 (state->err != Z_OK && state->err != Z_BUF_ERROR)) in gzgets()
504 if (state->seek) { in gzgets()
505 state->seek = 0; in gzgets()
506 if (gz_skip(state, state->skip) == -1) in gzgets()
517 if (state->x.have == 0 && gz_fetch(state) == -1) in gzgets()
519 if (state->x.have == 0) { /* end of file */ in gzgets()
520 state->past = 1; /* read past end */ in gzgets()
525 n = state->x.have > left ? left : state->x.have; in gzgets()
526 eol = (unsigned char *)memchr(state->x.next, '\n', n); in gzgets()
528 n = (unsigned)(eol - state->x.next) + 1; in gzgets()
531 memcpy(buf, state->x.next, n); in gzgets()
532 state->x.have -= n; in gzgets()
533 state->x.next += n; in gzgets()
534 state->x.pos += n; in gzgets()
550 gz_statep state; in gzdirect() local
555 state = (gz_statep)file; in gzdirect()
557 /* if the state is not known, but we can find out, then do so (this is in gzdirect()
559 if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0) in gzdirect()
560 (void)gz_look(state); in gzdirect()
563 return state->direct; in gzdirect()
571 gz_statep state; in gzclose_r() local
576 state = (gz_statep)file; in gzclose_r()
579 if (state->mode != GZ_READ) in gzclose_r()
583 if (state->size) { in gzclose_r()
584 inflateEnd(&(state->strm)); in gzclose_r()
585 free(state->out); in gzclose_r()
586 free(state->in); in gzclose_r()
588 err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK; in gzclose_r()
589 gz_error(state, Z_OK, NULL); in gzclose_r()
590 free(state->path); in gzclose_r()
591 ret = close(state->fd); in gzclose_r()
592 free(state); in gzclose_r()