Lines Matching refs:state
78 local void gz_reset(state) in gz_reset() argument
79 gz_statep state; in gz_reset()
81 state.state->x.have = 0; /* no output data available */
82 if (state.state->mode == GZ_READ) { /* for reading ... */
83 state.state->eof = 0; /* not at end of file */
84 state.state->past = 0; /* have not read past end yet */
85 state.state->how = LOOK; /* look for gzip header */
87 state.state->seek = 0; /* no seek request pending */
88 gz_error(state, Z_OK, NULL); /* clear error */
89 state.state->x.pos = 0; /* no uncompressed data yet */
90 state.state->strm.avail_in = 0; /* no input data yet */
99 gz_statep state; local
114 state.state = (gz_state*)malloc(sizeof(gz_state));
115 if (state.state == NULL)
117 state.state->size = 0; /* no buffers allocated yet */
118 state.state->want = GZBUFSIZE; /* requested buffer size */
119 state.state->msg = NULL; /* no error message yet */
122 state.state->mode = GZ_NONE;
123 state.state->level = Z_DEFAULT_COMPRESSION;
124 state.state->strategy = Z_DEFAULT_STRATEGY;
125 state.state->direct = 0;
128 state.state->level = *mode - '0';
132 state.state->mode = GZ_READ;
136 state.state->mode = GZ_WRITE;
139 state.state->mode = GZ_APPEND;
143 free(state.state);
158 state.state->strategy = Z_FILTERED;
161 state.state->strategy = Z_HUFFMAN_ONLY;
164 state.state->strategy = Z_RLE;
167 state.state->strategy = Z_FIXED;
170 state.state->direct = 1;
179 if (state.state->mode == GZ_NONE) {
180 free(state.state);
185 if (state.state->mode == GZ_READ) {
186 if (state.state->direct) {
187 free(state.state);
190 state.state->direct = 1; /* for empty file */
203 state.state->path = (char *)malloc(len + 1);
204 if (state.state->path == NULL) {
205 free(state.state);
211 wcstombs(state.state->path, path, len + 1);
213 *(state.state->path) = 0;
217 (void)snprintf(state.state->path, len + 1, "%s", (const char *)path);
219 strcpy(state.state->path, (const char*)path);
233 (state.state->mode == GZ_READ ?
239 (state.state->mode == GZ_WRITE ?
244 state.state->fd = fd > -1 ? fd : (
249 if (state.state->fd == -1) {
250 free(state.state->path);
251 free(state.state);
254 if (state.state->mode == GZ_APPEND) {
255 LSEEK(state.state->fd, 0, SEEK_END); /* so gzoffset() is correct */
256 state.state->mode = GZ_WRITE; /* simplify later checks */
260 if (state.state->mode == GZ_READ) {
261 state.state->start = LSEEK(state.state->fd, 0, SEEK_CUR);
262 if (state.state->start == -1) state.state->start = 0;
266 gz_reset(state);
269 return state.file;
323 gz_statep state; local
328 state.file = file;
329 if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
333 if (state.state->size != 0)
341 state.state->want = size;
349 gz_statep state; local
354 state.file = file;
357 if (state.state->mode != GZ_READ ||
358 (state.state->err != Z_OK && state.state->err != Z_BUF_ERROR))
362 if (LSEEK(state.state->fd, state.state->start, SEEK_SET) == -1)
364 gz_reset(state);
376 gz_statep state; local
381 state.file = file;
382 if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
386 if (state.state->err != Z_OK && state.state->err != Z_BUF_ERROR)
395 offset -= state.state->x.pos;
396 else if (state.state->seek)
397 offset += state.state->skip;
398 state.state->seek = 0;
401 if (state.state->mode == GZ_READ && state.state->how == COPY &&
402 state.state->x.pos + offset >= 0) {
403 ret = LSEEK(state.state->fd, offset - state.state->x.have, SEEK_CUR);
406 state.state->x.have = 0;
407 state.state->eof = 0;
408 state.state->past = 0;
409 state.state->seek = 0;
410 gz_error(state, Z_OK, NULL);
411 state.state->strm.avail_in = 0;
412 state.state->x.pos += offset;
413 return state.state->x.pos;
418 if (state.state->mode != GZ_READ) /* writing -- can't go backwards */
420 offset += state.state->x.pos;
428 if (state.state->mode == GZ_READ) {
429 n = GT_OFF(state.state->x.have) || (z_off64_t)state.state->x.have > offset ?
430 (unsigned)offset : state.state->x.have;
431 state.state->x.have -= n;
432 state.state->x.next += n;
433 state.state->x.pos += n;
439 state.state->seek = 1;
440 state.state->skip = offset;
442 return state.state->x.pos + offset;
461 gz_statep state; local
466 state.file = file;
467 if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
471 return state.state->x.pos + (state.state->seek ? state.state->skip : 0);
489 gz_statep state; local
494 state.file = file;
495 if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
499 offset = LSEEK(state.state->fd, 0, SEEK_CUR);
502 if (state.state->mode == GZ_READ) /* reading */
503 offset -= state.state->strm.avail_in; /* don't count buffered input */
521 gz_statep state; local
526 state.file = file;
527 if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
531 return state.state->mode == GZ_READ ? state.state->past : 0;
539 gz_statep state; local
544 state.file = file;
545 if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
550 *errnum = state.state->err;
551 return state.state->err == Z_MEM_ERROR ? "out of memory" :
552 (state.state->msg == NULL ? "" : state.state->msg);
559 gz_statep state; local
564 state.file = file;
565 if (state.state->mode != GZ_READ && state.state->mode != GZ_WRITE)
569 if (state.state->mode == GZ_READ) {
570 state.state->eof = 0;
571 state.state->past = 0;
573 gz_error(state, Z_OK, NULL);
582 void ZLIB_INTERNAL gz_error(state, err, msg) in gz_error() argument
583 gz_statep state; in gz_error()
588 if (state.state->msg != NULL) {
589 if (state.state->err != Z_MEM_ERROR)
590 free(state.state->msg);
591 state.state->msg = NULL;
596 state.state->x.have = 0;
599 state.state->err = err;
608 if ((state.state->msg = (char *)malloc(strlen(state.state->path) + strlen(msg) + 3)) ==
610 state.state->err = Z_MEM_ERROR;
614 (void)snprintf(state.state->msg, strlen(state.state->path) + strlen(msg) + 3,
615 "%s%s%s", state.state->path, ": ", msg);
617 strcpy(state.state->msg, state.state->path);
618 strcat(state.state->msg, ": ");
619 strcat(state.state->msg, msg);