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;
103 state = malloc(sizeof(gz_state));
104 if (state == NULL)
106 state->size = 0; /* no buffers allocated yet */
107 state->want = GZBUFSIZE; /* requested buffer size */
108 state->msg = NULL; /* no error message yet */
111 state->mode = GZ_NONE;
112 state->level = Z_DEFAULT_COMPRESSION;
113 state->strategy = Z_DEFAULT_STRATEGY;
114 state->direct = 0;
117 state->level = *mode - '0';
121 state->mode = GZ_READ;
125 state->mode = GZ_WRITE;
128 state->mode = GZ_APPEND;
132 free(state);
137 state->strategy = Z_FILTERED;
140 state->strategy = Z_HUFFMAN_ONLY;
143 state->strategy = Z_RLE;
146 state->strategy = Z_FIXED;
148 state->direct = 1;
156 if (state->mode == GZ_NONE) {
157 free(state);
162 if (state->mode == GZ_READ) {
163 if (state->direct) {
164 free(state);
167 state->direct = 1; /* for empty file */
171 state->path = malloc(strlen(path) + 1);
172 if (state->path == NULL) {
173 free(state);
176 strcpy(state->path, path);
179 state->fd = fd != -1 ? fd :
187 (state->mode == GZ_READ ?
190 state->mode == GZ_WRITE ?
194 if (state->fd == -1) {
195 free(state->path);
196 free(state);
199 if (state->mode == GZ_APPEND)
200 state->mode = GZ_WRITE; /* simplify later checks */
203 if (state->mode == GZ_READ) {
204 state->start = LSEEK(state->fd, 0, SEEK_CUR);
205 if (state->start == -1) state->start = 0;
209 gz_reset(state);
212 return (gzFile)state;
252 gz_statep state;
257 state = (gz_statep)file;
258 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
262 if (state->size != 0)
268 state->want = size;
276 gz_statep state;
281 state = (gz_statep)file;
284 if (state->mode != GZ_READ ||
285 (state->err != Z_OK && state->err != Z_BUF_ERROR))
289 if (LSEEK(state->fd, state->start, SEEK_SET) == -1)
291 gz_reset(state);
303 gz_statep state;
308 state = (gz_statep)file;
309 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
313 if (state->err != Z_OK && state->err != Z_BUF_ERROR)
322 offset -= state->x.pos;
323 else if (state->seek)
324 offset += state->skip;
325 state->seek = 0;
328 if (state->mode == GZ_READ && state->how == COPY &&
329 state->x.pos + offset >= 0) {
330 ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
333 state->x.have = 0;
334 state->eof = 0;
335 state->past = 0;
336 state->seek = 0;
337 gz_error(state, Z_OK, NULL);
338 state->strm.avail_in = 0;
339 state->x.pos += offset;
340 return state->x.pos;
345 if (state->mode != GZ_READ) /* writing -- can't go backwards */
347 offset += state->x.pos;
355 if (state->mode == GZ_READ) {
356 n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
357 (unsigned)offset : state->x.have;
358 state->x.have -= n;
359 state->x.next += n;
360 state->x.pos += n;
366 state->seek = 1;
367 state->skip = offset;
369 return state->x.pos + offset;
388 gz_statep state;
393 state = (gz_statep)file;
394 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
398 return state->x.pos + (state->seek ? state->skip : 0);
416 gz_statep state;
421 state = (gz_statep)file;
422 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
426 offset = LSEEK(state->fd, 0, SEEK_CUR);
429 if (state->mode == GZ_READ) /* reading */
430 offset -= state->strm.avail_in; /* don't count buffered input */
448 gz_statep state;
453 state = (gz_statep)file;
454 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
457 /* return end-of-file state */
458 return state->mode == GZ_READ ? state->past : 0;
466 gz_statep state;
471 state = (gz_statep)file;
472 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
477 *errnum = state->err;
478 return state->msg == NULL ? "" : state->msg;
485 gz_statep state;
490 state = (gz_statep)file;
491 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
495 if (state->mode == GZ_READ) {
496 state->eof = 0;
497 state->past = 0;
499 gz_error(state, Z_OK, NULL);
502 /* Create an error message in allocated memory and set state->err and
503 state->msg accordingly. Free any previous error message already there. Do
508 void ZLIB_INTERNAL gz_error(state, err, msg)
509 gz_statep state;
514 if (state->msg != NULL) {
515 if (state->err != Z_MEM_ERROR)
516 free(state->msg);
517 state->msg = NULL;
520 /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */
522 state->x.have = 0;
525 state->err = err;
531 state->msg = (char *)msg;
536 if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) {
537 state->err = Z_MEM_ERROR;
538 state->msg = (char *)"out of memory";
541 strcpy(state->msg, state->path);
542 strcat(state->msg, ": ");
543 strcat(state->msg, msg);