Lines Matching refs:state

75 local void gz_reset(state)  in gz_reset()  argument
76 gz_statep state; in gz_reset()
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; local
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 (void)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 LSEEK(state->fd, 0, SEEK_END); /* so gzoffset() is correct */
253 state->mode = GZ_WRITE; /* simplify later checks */
257 if (state->mode == GZ_READ) {
258 state->start = LSEEK(state->fd, 0, SEEK_CUR);
259 if (state->start == -1) state->start = 0;
263 gz_reset(state);
266 return (gzFile)state;
320 gz_statep state; local
325 state = (gz_statep)file;
326 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
330 if (state->size != 0)
338 state->want = size;
346 gz_statep state; local
351 state = (gz_statep)file;
354 if (state->mode != GZ_READ ||
355 (state->err != Z_OK && state->err != Z_BUF_ERROR))
359 if (LSEEK(state->fd, state->start, SEEK_SET) == -1)
361 gz_reset(state);
373 gz_statep state; local
378 state = (gz_statep)file;
379 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
383 if (state->err != Z_OK && state->err != Z_BUF_ERROR)
392 offset -= state->x.pos;
393 else if (state->seek)
394 offset += state->skip;
395 state->seek = 0;
398 if (state->mode == GZ_READ && state->how == COPY &&
399 state->x.pos + offset >= 0) {
400 ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
403 state->x.have = 0;
404 state->eof = 0;
405 state->past = 0;
406 state->seek = 0;
407 gz_error(state, Z_OK, NULL);
408 state->strm.avail_in = 0;
409 state->x.pos += offset;
410 return state->x.pos;
415 if (state->mode != GZ_READ) /* writing -- can't go backwards */
417 offset += state->x.pos;
425 if (state->mode == GZ_READ) {
426 n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
427 (unsigned)offset : state->x.have;
428 state->x.have -= n;
429 state->x.next += n;
430 state->x.pos += n;
436 state->seek = 1;
437 state->skip = offset;
439 return state->x.pos + offset;
458 gz_statep state; local
463 state = (gz_statep)file;
464 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
468 return state->x.pos + (state->seek ? state->skip : 0);
486 gz_statep state; local
491 state = (gz_statep)file;
492 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
496 offset = LSEEK(state->fd, 0, SEEK_CUR);
499 if (state->mode == GZ_READ) /* reading */
500 offset -= state->strm.avail_in; /* don't count buffered input */
518 gz_statep state; local
523 state = (gz_statep)file;
524 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
528 return state->mode == GZ_READ ? state->past : 0;
536 gz_statep state; local
541 state = (gz_statep)file;
542 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
547 *errnum = state->err;
548 return state->err == Z_MEM_ERROR ? "out of memory" :
549 (state->msg == NULL ? "" : state->msg);
556 gz_statep state; local
561 state = (gz_statep)file;
562 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
566 if (state->mode == GZ_READ) {
567 state->eof = 0;
568 state->past = 0;
570 gz_error(state, Z_OK, NULL);
579 void ZLIB_INTERNAL gz_error(state, err, msg) in gz_error() argument
580 gz_statep state; in gz_error()
585 if (state->msg != NULL) {
586 if (state->err != Z_MEM_ERROR)
587 free(state->msg);
588 state->msg = NULL;
593 state->x.have = 0;
596 state->err = err;
605 if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) ==
607 state->err = Z_MEM_ERROR;
611 (void)snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
612 "%s%s%s", state->path, ": ", msg);
614 strcpy(state->msg, state->path);
615 strcat(state->msg, ": ");
616 strcat(state->msg, msg);