• Home
  • Raw
  • Download

Lines Matching refs:state

32 local int gz_load(state, buf, len, have)  in gz_load()  argument
33 gz_statep state; in gz_load()
46 ret = read(state.state->fd, buf + *have, get);
52 gz_error(state, Z_ERRNO, zstrerror());
56 state.state->eof = 1;
67 local int gz_avail(state) in gz_avail() argument
68 gz_statep state; in gz_avail()
71 z_streamp strm = &(state.state->strm);
73 if (state.state->err != Z_OK && state.state->err != Z_BUF_ERROR)
75 if (state.state->eof == 0) {
77 unsigned char *p = state.state->in;
84 if (gz_load(state, state.state->in + strm->avail_in,
85 state.state->size - strm->avail_in, &got) == -1)
88 strm->next_in = state.state->in;
102 local int gz_look(state) in gz_look() argument
103 gz_statep state; in gz_look()
105 z_streamp strm = &(state.state->strm);
108 if (state.state->size == 0) {
110 state.state->in = (unsigned char *)malloc(state.state->want);
111 state.state->out = (unsigned char *)malloc(state.state->want << 1);
112 if (state.state->in == NULL || state.state->out == NULL) {
113 free(state.state->out);
114 free(state.state->in);
115 gz_error(state, Z_MEM_ERROR, "out of memory");
118 state.state->size = state.state->want;
121 state.state->strm.zalloc = Z_NULL;
122 state.state->strm.zfree = Z_NULL;
123 state.state->strm.opaque = Z_NULL;
124 state.state->strm.avail_in = 0;
125 state.state->strm.next_in = Z_NULL;
126 if (inflateInit2(&(state.state->strm), 15 + 16) != Z_OK) { /* gunzip */
127 free(state.state->out);
128 free(state.state->in);
129 state.state->size = 0;
130 gz_error(state, Z_MEM_ERROR, "out of memory");
137 if (gz_avail(state) == -1)
154 state.state->how = GZIP;
155 state.state->direct = 0;
161 if (state.state->direct == 0) {
163 state.state->eof = 1;
164 state.state->x.have = 0;
171 state.state->x.next = state.state->out;
173 memcpy(state.state->x.next, strm->next_in, strm->avail_in);
174 state.state->x.have = strm->avail_in;
177 state.state->how = COPY;
178 state.state->direct = 1;
187 local int gz_decomp(state) in gz_decomp() argument
188 gz_statep state; in gz_decomp()
192 z_streamp strm = &(state.state->strm);
198 if (strm->avail_in == 0 && gz_avail(state) == -1)
201 gz_error(state, Z_BUF_ERROR, "unexpected end of file");
208 gz_error(state, Z_STREAM_ERROR,
213 gz_error(state, Z_MEM_ERROR, "out of memory");
217 gz_error(state, Z_DATA_ERROR,
224 state.state->x.have = had - strm->avail_out;
225 state.state->x.next = strm->next_out - state.state->x.have;
229 state.state->how = LOOK;
241 local int gz_fetch(state) in gz_fetch() argument
242 gz_statep state; in gz_fetch()
244 z_streamp strm = &(state.state->strm);
247 switch(state.state->how) {
249 if (gz_look(state) == -1)
251 if (state.state->how == LOOK)
255 if (gz_load(state, state.state->out, state.state->size << 1, &(state.state->x.have))
258 state.state->x.next = state.state->out;
261 strm->avail_out = state.state->size << 1;
262 strm->next_out = state.state->out;
263 if (gz_decomp(state) == -1)
266 } while (state.state->x.have == 0 && (!state.state->eof || strm->avail_in));
271 local int gz_skip(state, len) in gz_skip() argument
272 gz_statep state; in gz_skip()
280 if (state.state->x.have) {
281 n = GT_OFF(state.state->x.have) || (z_off64_t)state.state->x.have > len ?
282 (unsigned)len : state.state->x.have;
283 state.state->x.have -= n;
284 state.state->x.next += n;
285 state.state->x.pos += n;
290 else if (state.state->eof && state.state->strm.avail_in == 0)
296 if (gz_fetch(state) == -1)
306 local z_size_t gz_read(state, buf, len) in gz_read() argument
307 gz_statep state; in gz_read()
319 if (state.state->seek) {
320 state.state->seek = 0;
321 if (gz_skip(state, state.state->skip) == -1)
334 if (state.state->x.have) {
335 if (state.state->x.have < n)
336 n = state.state->x.have;
337 memcpy(buf, state.state->x.next, n);
338 state.state->x.next += n;
339 state.state->x.have -= n;
343 else if (state.state->eof && state.state->strm.avail_in == 0) {
344 state.state->past = 1; /* tried to read past end */
350 else if (state.state->how == LOOK || n < (state.state->size << 1)) {
352 if (gz_fetch(state) == -1)
360 else if (state.state->how == COPY) { /* read directly */
361 if (gz_load(state, (unsigned char *)buf, n, &n) == -1)
367 state.state->strm.avail_out = n;
368 state.state->strm.next_out = (unsigned char *)buf;
369 if (gz_decomp(state) == -1)
371 n = state.state->x.have;
372 state.state->x.have = 0;
379 state.state->x.pos += n;
392 gz_statep state; local
397 state.file = file;
400 if (state.state->mode != GZ_READ ||
401 (state.state->err != Z_OK && state.state->err != Z_BUF_ERROR))
407 gz_error(state, Z_STREAM_ERROR, "request does not fit in an int");
412 len = (unsigned)gz_read(state, buf, len);
415 if (len == 0 && state.state->err != Z_OK && state.state->err != Z_BUF_ERROR)
430 gz_statep state; local
435 state.file = file;
438 if (state.state->mode != GZ_READ ||
439 (state.state->err != Z_OK && state.state->err != Z_BUF_ERROR))
445 gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
450 return len ? gz_read(state, buf, len) / size : 0;
476 gz_statep state; local
481 state.file = file;
484 if (state.state->mode != GZ_READ ||
485 (state.state->err != Z_OK && state.state->err != Z_BUF_ERROR))
489 if (state.state->x.have) {
490 state.state->x.have--;
491 state.state->x.pos++;
492 return *(state.state->x.next)++;
496 ret = (int)gz_read(state, buf, 1);
511 gz_statep state; local
516 state.file = file;
519 if (state.state->mode != GZ_READ ||
520 (state.state->err != Z_OK && state.state->err != Z_BUF_ERROR))
524 if (state.state->seek) {
525 state.state->seek = 0;
526 if (gz_skip(state, state.state->skip) == -1)
535 if (state.state->x.have == 0) {
536 state.state->x.have = 1;
537 state.state->x.next = state.state->out + (state.state->size << 1) - 1;
538 state.state->x.next[0] = (unsigned char)c;
539 state.state->x.pos--;
540 state.state->past = 0;
545 if (state.state->x.have == (state.state->size << 1)) {
546 gz_error(state, Z_DATA_ERROR, "out of room to push characters");
551 if (state.state->x.next == state.state->out) {
552 unsigned char *src = state.state->out + state.state->x.have;
553 unsigned char *dest = state.state->out + (state.state->size << 1);
554 while (src > state.state->out)
556 state.state->x.next = dest;
558 state.state->x.have++;
559 state.state->x.next--;
560 state.state->x.next[0] = (unsigned char)c;
561 state.state->x.pos--;
562 state.state->past = 0;
575 gz_statep state; local
580 state.file = file;
583 if (state.state->mode != GZ_READ ||
584 (state.state->err != Z_OK && state.state->err != Z_BUF_ERROR))
588 if (state.state->seek) {
589 state.state->seek = 0;
590 if (gz_skip(state, state.state->skip) == -1)
601 if (state.state->x.have == 0 && gz_fetch(state) == -1)
603 if (state.state->x.have == 0) { /* end of file */
604 state.state->past = 1; /* read past end */
609 n = state.state->x.have > left ? left : state.state->x.have;
610 eol = (unsigned char *)memchr(state.state->x.next, '\n', n);
612 n = (unsigned)(eol - state.state->x.next) + 1;
615 memcpy(buf, state.state->x.next, n);
616 state.state->x.have -= n;
617 state.state->x.next += n;
618 state.state->x.pos += n;
634 gz_statep state; local
639 state.file = file;
643 if (state.state->mode == GZ_READ && state.state->how == LOOK && state.state->x.have == 0)
644 (void)gz_look(state);
647 return state.state->direct;
655 gz_statep state; local
660 state.file = file;
663 if (state.state->mode != GZ_READ)
667 if (state.state->size) {
668 inflateEnd(&(state.state->strm));
669 free(state.state->out);
670 free(state.state->in);
672 err = state.state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
673 gz_error(state, Z_OK, NULL);
674 free(state.state->path);
675 ret = close(state.state->fd);
676 free(state.state);