• Home
  • Raw
  • Download

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;
452 gz_statep state; local
457 state = (gz_statep)file;
460 if (state->mode != GZ_READ ||
461 (state->err != Z_OK && state->err != Z_BUF_ERROR))
465 if (state->x.have) {
466 state->x.have--;
467 state->x.pos++;
468 return *(state->x.next)++;
472 ret = gz_read(state, buf, 1);
487 gz_statep state; local
492 state = (gz_statep)file;
495 if (state->mode != GZ_READ ||
496 (state->err != Z_OK && state->err != Z_BUF_ERROR))
500 if (state->seek) {
501 state->seek = 0;
502 if (gz_skip(state, state->skip) == -1)
511 if (state->x.have == 0) {
512 state->x.have = 1;
513 state->x.next = state->out + (state->size << 1) - 1;
514 state->x.next[0] = (unsigned char)c;
515 state->x.pos--;
516 state->past = 0;
521 if (state->x.have == (state->size << 1)) {
522 gz_error(state, Z_DATA_ERROR, "out of room to push characters");
527 if (state->x.next == state->out) {
528 unsigned char *src = state->out + state->x.have;
529 unsigned char *dest = state->out + (state->size << 1);
530 while (src > state->out)
532 state->x.next = dest;
534 state->x.have++;
535 state->x.next--;
536 state->x.next[0] = (unsigned char)c;
537 state->x.pos--;
538 state->past = 0;
551 gz_statep state; local
556 state = (gz_statep)file;
559 if (state->mode != GZ_READ ||
560 (state->err != Z_OK && state->err != Z_BUF_ERROR))
564 if (state->seek) {
565 state->seek = 0;
566 if (gz_skip(state, state->skip) == -1)
577 if (state->x.have == 0 && gz_fetch(state) == -1)
579 if (state->x.have == 0) { /* end of file */
580 state->past = 1; /* read past end */
585 n = state->x.have > left ? left : state->x.have;
586 eol = (unsigned char *)memchr(state->x.next, '\n', n);
588 n = (unsigned)(eol - state->x.next) + 1;
591 memcpy(buf, state->x.next, n);
592 state->x.have -= n;
593 state->x.next += n;
594 state->x.pos += n;
610 gz_statep state; local
615 state = (gz_statep)file;
619 if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
620 (void)gz_look(state);
623 return state->direct;
631 gz_statep state; local
636 state = (gz_statep)file;
639 if (state->mode != GZ_READ)
643 if (state->size) {
644 inflateEnd(&(state->strm));
645 free(state->out);
646 free(state->in);
648 err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
649 gz_error(state, Z_OK, NULL);
650 free(state->path);
651 ret = close(state->fd);
652 free(state);