Lines Matching refs:state
74 /* Reset gzip file state */
75 local void gz_reset(state)
76 gz_statep state;
78 state->x.have = 0; /* no output data available */
79 if (state->mode == GZ_READ) { /* for reading ... */
80 state->eof = 0; /* not at end of file */
81 state->past = 0; /* have not read past end yet */
82 state->how = LOOK; /* look for gzip header */
84 state->seek = 0; /* no seek request pending */
85 gz_error(state, Z_OK, NULL); /* clear error */
86 state->x.pos = 0; /* no uncompressed data yet */
87 state->strm.avail_in = 0; /* no input data yet */
96 gz_statep state;
111 state = (gz_statep)malloc(sizeof(gz_state));
112 if (state == NULL)
114 state->size = 0; /* no buffers allocated yet */
115 state->want = GZBUFSIZE; /* requested buffer size */
116 state->msg = NULL; /* no error message yet */
119 state->mode = GZ_NONE;
120 state->level = Z_DEFAULT_COMPRESSION;
121 state->strategy = Z_DEFAULT_STRATEGY;
122 state->direct = 0;
125 state->level = *mode - '0';
129 state->mode = GZ_READ;
133 state->mode = GZ_WRITE;
136 state->mode = GZ_APPEND;
140 free(state);
155 state->strategy = Z_FILTERED;
158 state->strategy = Z_HUFFMAN_ONLY;
161 state->strategy = Z_RLE;
164 state->strategy = Z_FIXED;
167 state->direct = 1;
176 if (state->mode == GZ_NONE) {
177 free(state);
182 if (state->mode == GZ_READ) {
183 if (state->direct) {
184 free(state);
187 state->direct = 1; /* for empty file */
200 state->path = (char *)malloc(len + 1);
201 if (state->path == NULL) {
202 free(state);
208 wcstombs(state->path, path, len + 1);
210 *(state->path) = 0;
214 snprintf(state->path, len + 1, "%s", (const char *)path);
216 strcpy(state->path, path);
230 (state->mode == GZ_READ ?
236 (state->mode == GZ_WRITE ?
241 state->fd = fd > -1 ? fd : (
246 if (state->fd == -1) {
247 free(state->path);
248 free(state);
251 if (state->mode == GZ_APPEND)
252 state->mode = GZ_WRITE; /* simplify later checks */
255 if (state->mode == GZ_READ) {
256 state->start = LSEEK(state->fd, 0, SEEK_CUR);
257 if (state->start == -1) state->start = 0;
261 gz_reset(state);
264 return (gzFile)state;
318 gz_statep state;
323 state = (gz_statep)file;
324 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
328 if (state->size != 0)
334 state->want = size;
342 gz_statep state;
347 state = (gz_statep)file;
350 if (state->mode != GZ_READ ||
351 (state->err != Z_OK && state->err != Z_BUF_ERROR))
355 if (LSEEK(state->fd, state->start, SEEK_SET) == -1)
357 gz_reset(state);
369 gz_statep state;
374 state = (gz_statep)file;
375 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
379 if (state->err != Z_OK && state->err != Z_BUF_ERROR)
388 offset -= state->x.pos;
389 else if (state->seek)
390 offset += state->skip;
391 state->seek = 0;
394 if (state->mode == GZ_READ && state->how == COPY &&
395 state->x.pos + offset >= 0) {
396 ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
399 state->x.have = 0;
400 state->eof = 0;
401 state->past = 0;
402 state->seek = 0;
403 gz_error(state, Z_OK, NULL);
404 state->strm.avail_in = 0;
405 state->x.pos += offset;
406 return state->x.pos;
411 if (state->mode != GZ_READ) /* writing -- can't go backwards */
413 offset += state->x.pos;
421 if (state->mode == GZ_READ) {
422 n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
423 (unsigned)offset : state->x.have;
424 state->x.have -= n;
425 state->x.next += n;
426 state->x.pos += n;
432 state->seek = 1;
433 state->skip = offset;
435 return state->x.pos + offset;
454 gz_statep state;
459 state = (gz_statep)file;
460 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
464 return state->x.pos + (state->seek ? state->skip : 0);
482 gz_statep state;
487 state = (gz_statep)file;
488 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
492 offset = LSEEK(state->fd, 0, SEEK_CUR);
495 if (state->mode == GZ_READ) /* reading */
496 offset -= state->strm.avail_in; /* don't count buffered input */
514 gz_statep state;
519 state = (gz_statep)file;
520 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
523 /* return end-of-file state */
524 return state->mode == GZ_READ ? state->past : 0;
532 gz_statep state;
537 state = (gz_statep)file;
538 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
543 *errnum = state->err;
544 return state->err == Z_MEM_ERROR ? "out of memory" :
545 (state->msg == NULL ? "" : state->msg);
552 gz_statep state;
557 state = (gz_statep)file;
558 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
562 if (state->mode == GZ_READ) {
563 state->eof = 0;
564 state->past = 0;
566 gz_error(state, Z_OK, NULL);
569 /* Create an error message in allocated memory and set state->err and
570 state->msg accordingly. Free any previous error message already there. Do
575 void ZLIB_INTERNAL gz_error(state, err, msg)
576 gz_statep state;
581 if (state->msg != NULL) {
582 if (state->err != Z_MEM_ERROR)
583 free(state->msg);
584 state->msg = NULL;
587 /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */
589 state->x.have = 0;
592 state->err = err;
601 if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) ==
603 state->err = Z_MEM_ERROR;
607 snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
608 "%s%s%s", state->path, ": ", msg);
610 strcpy(state->msg, state->path);
611 strcat(state->msg, ": ");
612 strcat(state->msg, msg);