Lines Matching refs:state
13 /* Initialize state for writing a gzip file. Mark initialization by setting
14 state->size to non-zero. Return -1 on failure or 0 on success. */
15 local int gz_init(state)
16 gz_statep state;
19 z_streamp strm = &(state->strm);
22 state->in = malloc(state->want);
23 if (state->in == NULL) {
24 gz_error(state, Z_MEM_ERROR, "out of memory");
28 /* only need output buffer and deflate state if compressing */
29 if (!state->direct) {
31 state->out = malloc(state->want);
32 if (state->out == NULL) {
33 free(state->in);
34 gz_error(state, Z_MEM_ERROR, "out of memory");
42 ret = deflateInit2(strm, state->level, Z_DEFLATED,
43 MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
45 free(state->out);
46 free(state->in);
47 gz_error(state, Z_MEM_ERROR, "out of memory");
52 /* mark state as initialized */
53 state->size = state->want;
56 if (!state->direct) {
57 strm->avail_out = state->size;
58 strm->next_out = state->out;
59 state->x.next = strm->next_out;
67 then the deflate() state is reset to start a new gzip stream. If gz->direct
70 local int gz_comp(state, flush)
71 gz_statep state;
76 z_streamp strm = &(state->strm);
79 if (state->size == 0 && gz_init(state) == -1)
83 if (state->direct) {
84 got = write(state->fd, strm->next_in, strm->avail_in);
86 gz_error(state, Z_ERRNO, zstrerror());
100 have = (unsigned)(strm->next_out - state->x.next);
101 if (have && ((got = write(state->fd, state->x.next, have)) < 0 ||
103 gz_error(state, Z_ERRNO, zstrerror());
107 strm->avail_out = state->size;
108 strm->next_out = state->out;
110 state->x.next = strm->next_out;
117 gz_error(state, Z_STREAM_ERROR,
133 local int gz_zero(state, len)
134 gz_statep state;
139 z_streamp strm = &(state->strm);
142 if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
148 n = GT_OFF(state->size) || (z_off64_t)state->size > len ?
149 (unsigned)len : state->size;
151 memset(state->in, 0, n);
155 strm->next_in = state->in;
156 state->x.pos += n;
157 if (gz_comp(state, Z_NO_FLUSH) == -1)
172 gz_statep state;
178 state = (gz_statep)file;
179 strm = &(state->strm);
182 if (state->mode != GZ_WRITE || state->err != Z_OK)
188 gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
197 if (state->size == 0 && gz_init(state) == -1)
201 if (state->seek) {
202 state->seek = 0;
203 if (gz_zero(state, state->skip) == -1)
208 if (len < state->size) {
212 strm->next_in = state->in;
213 n = state->size - strm->avail_in;
218 state->x.pos += n;
221 if (len && gz_comp(state, Z_NO_FLUSH) == -1)
227 if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
233 state->x.pos += len;
234 if (gz_comp(state, Z_NO_FLUSH) == -1)
248 gz_statep state;
254 state = (gz_statep)file;
255 strm = &(state->strm);
258 if (state->mode != GZ_WRITE || state->err != Z_OK)
262 if (state->seek) {
263 state->seek = 0;
264 if (gz_zero(state, state->skip) == -1)
268 /* try writing to input buffer for speed (state->size == 0 if buffer not
270 if (strm->avail_in < state->size) {
272 strm->next_in = state->in;
274 state->x.pos++;
306 gz_statep state;
313 state = (gz_statep)file;
314 strm = &(state->strm);
317 if (state->mode != GZ_WRITE || state->err != Z_OK)
321 if (state->size == 0 && gz_init(state) == -1)
325 if (state->seek) {
326 state->seek = 0;
327 if (gz_zero(state, state->skip) == -1)
332 if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
336 size = (int)(state->size);
337 state->in[size - 1] = 0;
341 (void)vsprintf(state->in, format, va);
344 if (state->in[len] == 0) break;
346 len = vsprintf(state->in, format, va);
351 (void)vsnprintf(state->in, size, format, va);
353 len = strlen(state->in);
355 len = vsnprintf((char *)(state->in), size, format, va);
361 if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
366 strm->next_in = state->in;
367 state->x.pos += len;
382 gz_statep state;
388 state = (gz_statep)file;
389 strm = &(state->strm);
396 if (state->mode != GZ_WRITE || state->err != Z_OK)
400 if (state->size == 0 && gz_init(state) == -1)
404 if (state->seek) {
405 state->seek = 0;
406 if (gz_zero(state, state->skip) == -1)
411 if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
415 size = (int)(state->size);
416 state->in[size - 1] = 0;
419 sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8,
422 if (state->in[len] == 0) break;
424 len = sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8,
429 snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8,
431 len = strlen(state->in);
433 len = snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8,
439 if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
444 strm->next_in = state->in;
445 state->x.pos += len;
456 gz_statep state;
461 state = (gz_statep)file;
464 if (state->mode != GZ_WRITE || state->err != Z_OK)
472 if (state->seek) {
473 state->seek = 0;
474 if (gz_zero(state, state->skip) == -1)
479 gz_comp(state, flush);
480 return state->err;
489 gz_statep state;
495 state = (gz_statep)file;
496 strm = &(state->strm);
499 if (state->mode != GZ_WRITE || state->err != Z_OK)
503 if (level == state->level && strategy == state->strategy)
507 if (state->seek) {
508 state->seek = 0;
509 if (gz_zero(state, state->skip) == -1)
514 if (state->size) {
516 if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1)
517 return state->err;
520 state->level = level;
521 state->strategy = strategy;
530 gz_statep state;
535 state = (gz_statep)file;
538 if (state->mode != GZ_WRITE)
542 if (state->seek) {
543 state->seek = 0;
544 if (gz_zero(state, state->skip) == -1)
545 ret = state->err;
549 if (gz_comp(state, Z_FINISH) == -1)
550 ret = state->err;
551 if (!state->direct) {
552 (void)deflateEnd(&(state->strm));
553 free(state->out);
555 free(state->in);
556 gz_error(state, Z_OK, NULL);
557 free(state->path);
558 if (close(state->fd) == -1)
560 free(state);