• Home
  • Raw
  • Download

Lines Matching refs:state

22 static int gz_load(gz_state *state, unsigned char *buf, unsigned len, unsigned *have) {  in gz_load()  argument
27 ret = read(state->fd, buf + *have, len - *have); in gz_load()
33 gz_error(state, Z_ERRNO, zstrerror()); in gz_load()
37 state->eof = 1; in gz_load()
48 static int gz_avail(gz_state *state) { in gz_avail() argument
50 PREFIX3(stream) *strm = &(state->strm); in gz_avail()
52 if (state->err != Z_OK && state->err != Z_BUF_ERROR) in gz_avail()
54 if (state->eof == 0) { in gz_avail()
56 unsigned char *p = state->in; in gz_avail()
63 if (gz_load(state, state->in + strm->avail_in, state->size - strm->avail_in, &got) == -1) in gz_avail()
66 strm->next_in = state->in; in gz_avail()
80 static int gz_look(gz_state *state) { in gz_look() argument
81 PREFIX3(stream) *strm = &(state->strm); in gz_look()
84 if (state->size == 0) { in gz_look()
86 state->in = (unsigned char *)malloc(state->want); in gz_look()
87 state->out = (unsigned char *)malloc(state->want << 1); in gz_look()
88 if (state->in == NULL || state->out == NULL) { in gz_look()
89 free(state->out); in gz_look()
90 free(state->in); in gz_look()
91 gz_error(state, Z_MEM_ERROR, "out of memory"); in gz_look()
94 state->size = state->want; in gz_look()
97 state->strm.zalloc = NULL; in gz_look()
98 state->strm.zfree = NULL; in gz_look()
99 state->strm.opaque = NULL; in gz_look()
100 state->strm.avail_in = 0; in gz_look()
101 state->strm.next_in = NULL; in gz_look()
102 if (PREFIX(inflateInit2)(&(state->strm), 15 + 16) != Z_OK) { /* gunzip */ in gz_look()
103 free(state->out); in gz_look()
104 free(state->in); in gz_look()
105 state->size = 0; in gz_look()
106 gz_error(state, Z_MEM_ERROR, "out of memory"); in gz_look()
113 if (gz_avail(state) == -1) in gz_look()
129 state->how = GZIP; in gz_look()
130 state->direct = 0; in gz_look()
136 if (state->direct == 0) { in gz_look()
138 state->eof = 1; in gz_look()
139 state->x.have = 0; in gz_look()
146 state->x.next = state->out; in gz_look()
148 memcpy(state->x.next, strm->next_in, strm->avail_in); in gz_look()
149 state->x.have = strm->avail_in; in gz_look()
152 state->how = COPY; in gz_look()
153 state->direct = 1; in gz_look()
162 static int gz_decomp(gz_state *state) { in gz_decomp() argument
165 PREFIX3(stream) *strm = &(state->strm); in gz_decomp()
171 if (strm->avail_in == 0 && gz_avail(state) == -1) in gz_decomp()
174 gz_error(state, Z_BUF_ERROR, "unexpected end of file"); in gz_decomp()
181 gz_error(state, Z_STREAM_ERROR, "internal error: inflate stream corrupt"); in gz_decomp()
185 gz_error(state, Z_MEM_ERROR, "out of memory"); in gz_decomp()
189 gz_error(state, Z_DATA_ERROR, strm->msg == NULL ? "compressed data error" : strm->msg); in gz_decomp()
195 state->x.have = had - strm->avail_out; in gz_decomp()
196 state->x.next = strm->next_out - state->x.have; in gz_decomp()
200 state->how = LOOK; in gz_decomp()
212 static int gz_fetch(gz_state *state) { in gz_fetch() argument
213 PREFIX3(stream) *strm = &(state->strm); in gz_fetch()
216 switch (state->how) { in gz_fetch()
218 if (gz_look(state) == -1) in gz_fetch()
220 if (state->how == LOOK) in gz_fetch()
224 if (gz_load(state, state->out, state->size << 1, &(state->x.have)) in gz_fetch()
227 state->x.next = state->out; in gz_fetch()
230 strm->avail_out = state->size << 1; in gz_fetch()
231 strm->next_out = state->out; in gz_fetch()
232 if (gz_decomp(state) == -1) in gz_fetch()
235 } while (state->x.have == 0 && (!state->eof || strm->avail_in)); in gz_fetch()
240 static int gz_skip(gz_state *state, z_off64_t len) { in gz_skip() argument
246 if (state->x.have) { in gz_skip()
247 n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ? in gz_skip()
248 (unsigned)len : state->x.have; in gz_skip()
249 state->x.have -= n; in gz_skip()
250 state->x.next += n; in gz_skip()
251 state->x.pos += n; in gz_skip()
253 } else if (state->eof && state->strm.avail_in == 0) { in gz_skip()
259 if (gz_fetch(state) == -1) in gz_skip()
269 static size_t gz_read(gz_state *state, void *buf, size_t len) { in gz_read() argument
278 if (state->seek) { in gz_read()
279 state->seek = 0; in gz_read()
280 if (gz_skip(state, state->skip) == -1) in gz_read()
293 if (state->x.have) { in gz_read()
294 if (state->x.have < n) in gz_read()
295 n = state->x.have; in gz_read()
296 memcpy(buf, state->x.next, n); in gz_read()
297 state->x.next += n; in gz_read()
298 state->x.have -= n; in gz_read()
302 else if (state->eof && state->strm.avail_in == 0) { in gz_read()
303 state->past = 1; /* tried to read past end */ in gz_read()
309 else if (state->how == LOOK || n < (state->size << 1)) { in gz_read()
311 if (gz_fetch(state) == -1) in gz_read()
319 else if (state->how == COPY) { /* read directly */ in gz_read()
320 if (gz_load(state, (unsigned char *)buf, n, &n) == -1) in gz_read()
326 state->strm.avail_out = n; in gz_read()
327 state->strm.next_out = (unsigned char *)buf; in gz_read()
328 if (gz_decomp(state) == -1) in gz_read()
330 n = state->x.have; in gz_read()
331 state->x.have = 0; in gz_read()
338 state->x.pos += n; in gz_read()
347 gz_state *state; in PREFIX() local
352 state = (gz_state *)file; in PREFIX()
355 if (state->mode != GZ_READ || in PREFIX()
356 (state->err != Z_OK && state->err != Z_BUF_ERROR)) in PREFIX()
362 gz_error(state, Z_STREAM_ERROR, "request does not fit in an int"); in PREFIX()
367 len = (unsigned)gz_read(state, buf, len); in PREFIX()
370 if (len == 0 && state->err != Z_OK && state->err != Z_BUF_ERROR) in PREFIX()
380 gz_state *state; in PREFIX() local
389 state = (gz_state *)file; in PREFIX()
392 if (state->mode != GZ_READ || in PREFIX()
393 (state->err != Z_OK && state->err != Z_BUF_ERROR)) in PREFIX()
399 gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t"); in PREFIX()
404 return len ? gz_read(state, buf, len) / size : 0; in PREFIX()
412 gz_state *state; in PREFIX() local
417 state = (gz_state *)file; in PREFIX()
420 if (state->mode != GZ_READ || (state->err != Z_OK && state->err != Z_BUF_ERROR)) in PREFIX()
424 if (state->x.have) { in PREFIX()
425 state->x.have--; in PREFIX()
426 state->x.pos++; in PREFIX()
427 return *(state->x.next)++; in PREFIX()
431 return gz_read(state, buf, 1) < 1 ? -1 : buf[0]; in PREFIX()
440 gz_state *state; in PREFIX() local
445 state = (gz_state *)file; in PREFIX()
448 if (state->mode != GZ_READ || (state->err != Z_OK && state->err != Z_BUF_ERROR)) in PREFIX()
452 if (state->seek) { in PREFIX()
453 state->seek = 0; in PREFIX()
454 if (gz_skip(state, state->skip) == -1) in PREFIX()
463 if (state->x.have == 0) { in PREFIX()
464 state->x.have = 1; in PREFIX()
465 state->x.next = state->out + (state->size << 1) - 1; in PREFIX()
466 state->x.next[0] = (unsigned char)c; in PREFIX()
467 state->x.pos--; in PREFIX()
468 state->past = 0; in PREFIX()
473 if (state->x.have == (state->size << 1)) { in PREFIX()
474 gz_error(state, Z_DATA_ERROR, "out of room to push characters"); in PREFIX()
479 if (state->x.next == state->out) { in PREFIX()
480 unsigned char *src = state->out + state->x.have; in PREFIX()
481 unsigned char *dest = state->out + (state->size << 1); in PREFIX()
482 while (src > state->out) in PREFIX()
484 state->x.next = dest; in PREFIX()
486 state->x.have++; in PREFIX()
487 state->x.next--; in PREFIX()
488 state->x.next[0] = (unsigned char)c; in PREFIX()
489 state->x.pos--; in PREFIX()
490 state->past = 0; in PREFIX()
499 gz_state *state; in PREFIX() local
504 state = (gz_state *)file; in PREFIX()
507 if (state->mode != GZ_READ || (state->err != Z_OK && state->err != Z_BUF_ERROR)) in PREFIX()
511 if (state->seek) { in PREFIX()
512 state->seek = 0; in PREFIX()
513 if (gz_skip(state, state->skip) == -1) in PREFIX()
525 if (state->x.have == 0 && gz_fetch(state) == -1) in PREFIX()
527 if (state->x.have == 0) { /* end of file */ in PREFIX()
528 state->past = 1; /* read past end */ in PREFIX()
533 n = state->x.have > left ? left : state->x.have; in PREFIX()
534 eol = (unsigned char *)memchr(state->x.next, '\n', n); in PREFIX()
536 n = (unsigned)(eol - state->x.next) + 1; in PREFIX()
539 memcpy(buf, state->x.next, n); in PREFIX()
540 state->x.have -= n; in PREFIX()
541 state->x.next += n; in PREFIX()
542 state->x.pos += n; in PREFIX()
557 gz_state *state; in PREFIX() local
563 state = (gz_state *)file; in PREFIX()
567 if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0) in PREFIX()
568 (void)gz_look(state); in PREFIX()
571 return state->direct; in PREFIX()
577 gz_state *state; in PREFIX() local
583 state = (gz_state *)file; in PREFIX()
586 if (state->mode != GZ_READ) in PREFIX()
590 if (state->size) { in PREFIX()
591 PREFIX(inflateEnd)(&(state->strm)); in PREFIX()
592 free(state->out); in PREFIX()
593 free(state->in); in PREFIX()
595 err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK; in PREFIX()
596 gz_error(state, Z_OK, NULL); in PREFIX()
597 free(state->path); in PREFIX()
598 ret = close(state->fd); in PREFIX()
599 free(state); in PREFIX()