Lines Matching refs:state

17 local int gz_init(state)  in gz_init()  argument
18 gz_statep state; in gz_init()
21 z_streamp strm = &(state->strm);
24 state->in = (unsigned char *)malloc(state->want << 1);
25 if (state->in == NULL) {
26 gz_error(state, Z_MEM_ERROR, "out of memory");
31 if (!state->direct) {
33 state->out = (unsigned char *)malloc(state->want);
34 if (state->out == NULL) {
35 free(state->in);
36 gz_error(state, Z_MEM_ERROR, "out of memory");
44 ret = deflateInit2(strm, state->level, Z_DEFLATED,
45 MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
47 free(state->out);
48 free(state->in);
49 gz_error(state, Z_MEM_ERROR, "out of memory");
56 state->size = state->want;
59 if (!state->direct) {
60 strm->avail_out = state->size;
61 strm->next_out = state->out;
62 state->x.next = strm->next_out;
73 local int gz_comp(state, flush) in gz_comp() argument
74 gz_statep state; in gz_comp()
79 z_streamp strm = &(state->strm);
82 if (state->size == 0 && gz_init(state) == -1)
86 if (state->direct) {
89 writ = write(state->fd, strm->next_in, put);
91 gz_error(state, Z_ERRNO, zstrerror());
107 while (strm->next_out > state->x.next) {
108 put = strm->next_out - state->x.next > (int)max ? max :
109 (unsigned)(strm->next_out - state->x.next);
110 writ = write(state->fd, state->x.next, put);
112 gz_error(state, Z_ERRNO, zstrerror());
115 state->x.next += writ;
118 strm->avail_out = state->size;
119 strm->next_out = state->out;
120 state->x.next = state->out;
128 gz_error(state, Z_STREAM_ERROR,
145 local int gz_zero(state, len) in gz_zero() argument
146 gz_statep state; in gz_zero()
151 z_streamp strm = &(state->strm);
154 if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
160 n = GT_OFF(state->size) || (z_off64_t)state->size > len ?
161 (unsigned)len : state->size;
163 memset(state->in, 0, n);
167 strm->next_in = state->in;
168 state->x.pos += n;
169 if (gz_comp(state, Z_NO_FLUSH) == -1)
178 local z_size_t gz_write(state, buf, len) in gz_write() argument
179 gz_statep state; in gz_write()
190 if (state->size == 0 && gz_init(state) == -1)
194 if (state->seek) {
195 state->seek = 0;
196 if (gz_zero(state, state->skip) == -1)
201 if (len < state->size) {
206 if (state->strm.avail_in == 0)
207 state->strm.next_in = state->in;
208 have = (unsigned)((state->strm.next_in + state->strm.avail_in) -
209 state->in);
210 copy = state->size - have;
213 memcpy(state->in + have, buf, copy);
214 state->strm.avail_in += copy;
215 state->x.pos += copy;
218 if (len && gz_comp(state, Z_NO_FLUSH) == -1)
224 if (state->strm.avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
228 state->strm.next_in = (z_const Bytef *)buf;
233 state->strm.avail_in = n;
234 state->x.pos += n;
235 if (gz_comp(state, Z_NO_FLUSH) == -1)
251 gz_statep state; local
256 state = (gz_statep)file;
259 if (state->mode != GZ_WRITE || state->err != Z_OK)
265 gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
270 return (int)gz_write(state, buf, len);
281 gz_statep state; local
286 state = (gz_statep)file;
289 if (state->mode != GZ_WRITE || state->err != Z_OK)
295 gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
300 return len ? gz_write(state, buf, len) / size : 0;
310 gz_statep state; local
316 state = (gz_statep)file;
317 strm = &(state->strm);
320 if (state->mode != GZ_WRITE || state->err != Z_OK)
324 if (state->seek) {
325 state->seek = 0;
326 if (gz_zero(state, state->skip) == -1)
332 if (state->size) {
334 strm->next_in = state->in;
335 have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
336 if (have < state->size) {
337 state->in[have] = (unsigned char)c;
339 state->x.pos++;
346 if (gz_write(state, buf, 1) != 1)
358 gz_statep state; local
363 state = (gz_statep)file;
366 if (state->mode != GZ_WRITE || state->err != Z_OK)
371 ret = gz_write(state, str, len);
384 gz_statep state; in gzvprintf() local
390 state = (gz_statep)file; in gzvprintf()
391 strm = &(state->strm); in gzvprintf()
394 if (state->mode != GZ_WRITE || state->err != Z_OK) in gzvprintf()
398 if (state->size == 0 && gz_init(state) == -1) in gzvprintf()
399 return state->err; in gzvprintf()
402 if (state->seek) { in gzvprintf()
403 state->seek = 0; in gzvprintf()
404 if (gz_zero(state, state->skip) == -1) in gzvprintf()
405 return state->err; in gzvprintf()
412 strm->next_in = state->in; in gzvprintf()
413 next = (char *)(state->in + (strm->next_in - state->in) + strm->avail_in); in gzvprintf()
414 next[state->size - 1] = 0; in gzvprintf()
418 for (len = 0; len < state->size; len++) in gzvprintf()
425 (void)vsnprintf(next, state->size, format, va); in gzvprintf()
428 len = vsnprintf(next, state->size, format, va); in gzvprintf()
433 if (len == 0 || (unsigned)len >= state->size || next[state->size - 1] != 0) in gzvprintf()
438 state->x.pos += len; in gzvprintf()
439 if (strm->avail_in >= state->size) { in gzvprintf()
440 left = strm->avail_in - state->size; in gzvprintf()
441 strm->avail_in = state->size; in gzvprintf()
442 if (gz_comp(state, Z_NO_FLUSH) == -1) in gzvprintf()
443 return state->err; in gzvprintf()
444 memcpy(state->in, state->in + state->size, left); in gzvprintf()
445 strm->next_in = state->in; in gzvprintf()
474 gz_statep state; local
480 state = (gz_statep)file;
481 strm = &(state->strm);
488 if (state->mode != GZ_WRITE || state->err != Z_OK)
492 if (state->size == 0 && gz_init(state) == -1)
493 return state->error;
496 if (state->seek) {
497 state->seek = 0;
498 if (gz_zero(state, state->skip) == -1)
499 return state->error;
506 strm->next_in = state->in;
508 next[state->size - 1] = 0;
522 snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8, a9,
526 len = snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8,
532 if (len == 0 || len >= state->size || next[state->size - 1] != 0)
537 state->x.pos += len;
538 if (strm->avail_in >= state->size) {
539 left = strm->avail_in - state->size;
540 strm->avail_in = state->size;
541 if (gz_comp(state, Z_NO_FLUSH) == -1)
542 return state->err;
543 memcpy(state->in, state->in + state->size, left);
544 strm->next_in = state->in;
557 gz_statep state; local
562 state = (gz_statep)file;
565 if (state->mode != GZ_WRITE || state->err != Z_OK)
573 if (state->seek) {
574 state->seek = 0;
575 if (gz_zero(state, state->skip) == -1)
576 return state->err;
580 (void)gz_comp(state, flush);
581 return state->err;
590 gz_statep state; local
596 state = (gz_statep)file;
597 strm = &(state->strm);
600 if (state->mode != GZ_WRITE || state->err != Z_OK)
604 if (level == state->level && strategy == state->strategy)
608 if (state->seek) {
609 state->seek = 0;
610 if (gz_zero(state, state->skip) == -1)
611 return state->err;
615 if (state->size) {
617 if (strm->avail_in && gz_comp(state, Z_BLOCK) == -1)
618 return state->err;
621 state->level = level;
622 state->strategy = strategy;
631 gz_statep state; local
636 state = (gz_statep)file;
639 if (state->mode != GZ_WRITE)
643 if (state->seek) {
644 state->seek = 0;
645 if (gz_zero(state, state->skip) == -1)
646 ret = state->err;
650 if (gz_comp(state, Z_FINISH) == -1)
651 ret = state->err;
652 if (state->size) {
653 if (!state->direct) {
654 (void)deflateEnd(&(state->strm));
655 free(state->out);
657 free(state->in);
659 gz_error(state, Z_OK, NULL);
660 free(state->path);
661 if (close(state->fd) == -1)
663 free(state);