Lines Matching refs:state

15 local int gz_init(state)  in gz_init()  argument
16 gz_statep state; in gz_init()
19 z_streamp strm = &(state->strm);
22 state->in = (unsigned char *)malloc(state->want);
23 if (state->in == NULL) {
24 gz_error(state, Z_MEM_ERROR, "out of memory");
29 if (!state->direct) {
31 state->out = (unsigned char *)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");
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;
70 local int gz_comp(state, flush) in gz_comp() argument
71 gz_statep state; in gz_comp()
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) in gz_zero() argument
134 gz_statep state; in gz_zero()
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)
171 gz_statep state; local
177 state = (gz_statep)file;
178 strm = &(state->strm);
181 if (state->mode != GZ_WRITE || state->err != Z_OK)
187 gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
196 if (state->size == 0 && gz_init(state) == -1)
200 if (state->seek) {
201 state->seek = 0;
202 if (gz_zero(state, state->skip) == -1)
207 if (len < state->size) {
213 strm->next_in = state->in;
214 have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
215 copy = state->size - have;
218 memcpy(state->in + have, buf, copy);
220 state->x.pos += copy;
223 if (len && gz_comp(state, Z_NO_FLUSH) == -1)
229 if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
235 state->x.pos += len;
236 if (gz_comp(state, Z_NO_FLUSH) == -1)
251 gz_statep state; local
257 state = (gz_statep)file;
258 strm = &(state->strm);
261 if (state->mode != GZ_WRITE || state->err != Z_OK)
265 if (state->seek) {
266 state->seek = 0;
267 if (gz_zero(state, state->skip) == -1)
273 if (state->size) {
275 strm->next_in = state->in;
276 have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
277 if (have < state->size) {
278 state->in[have] = c;
280 state->x.pos++;
313 gz_statep state; in gzvprintf() local
319 state = (gz_statep)file; in gzvprintf()
320 strm = &(state->strm); in gzvprintf()
323 if (state->mode != GZ_WRITE || state->err != Z_OK) in gzvprintf()
327 if (state->size == 0 && gz_init(state) == -1) in gzvprintf()
331 if (state->seek) { in gzvprintf()
332 state->seek = 0; in gzvprintf()
333 if (gz_zero(state, state->skip) == -1) in gzvprintf()
338 if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) in gzvprintf()
342 size = (int)(state->size); in gzvprintf()
343 state->in[size - 1] = 0; in gzvprintf()
346 (void)vsprintf((char *)(state->in), format, va); in gzvprintf()
348 if (state->in[len] == 0) break; in gzvprintf()
350 len = vsprintf((char *)(state->in), format, va); in gzvprintf()
354 (void)vsnprintf((char *)(state->in), size, format, va); in gzvprintf()
355 len = strlen((char *)(state->in)); in gzvprintf()
357 len = vsnprintf((char *)(state->in), size, format, va); in gzvprintf()
362 if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) in gzvprintf()
367 strm->next_in = state->in; in gzvprintf()
368 state->x.pos += len; in gzvprintf()
394 gz_statep state; local
400 state = (gz_statep)file;
401 strm = &(state->strm);
408 if (state->mode != GZ_WRITE || state->err != Z_OK)
412 if (state->size == 0 && gz_init(state) == -1)
416 if (state->seek) {
417 state->seek = 0;
418 if (gz_zero(state, state->skip) == -1)
423 if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
427 size = (int)(state->size);
428 state->in[size - 1] = 0;
431 sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
434 if (state->in[len] == 0) break;
436 len = sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
441 snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, a7, a8,
443 len = strlen((char *)(state->in));
445 len = snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6,
452 if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
457 strm->next_in = state->in;
458 state->x.pos += len;
469 gz_statep state; local
474 state = (gz_statep)file;
477 if (state->mode != GZ_WRITE || state->err != Z_OK)
485 if (state->seek) {
486 state->seek = 0;
487 if (gz_zero(state, state->skip) == -1)
492 gz_comp(state, flush);
493 return state->err;
502 gz_statep state; local
508 state = (gz_statep)file;
509 strm = &(state->strm);
512 if (state->mode != GZ_WRITE || state->err != Z_OK)
516 if (level == state->level && strategy == state->strategy)
520 if (state->seek) {
521 state->seek = 0;
522 if (gz_zero(state, state->skip) == -1)
527 if (state->size) {
529 if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1)
530 return state->err;
533 state->level = level;
534 state->strategy = strategy;
543 gz_statep state; local
548 state = (gz_statep)file;
551 if (state->mode != GZ_WRITE)
555 if (state->seek) {
556 state->seek = 0;
557 if (gz_zero(state, state->skip) == -1)
558 ret = state->err;
562 if (gz_comp(state, Z_FINISH) == -1)
563 ret = state->err;
564 if (state->size) {
565 if (!state->direct) {
566 (void)deflateEnd(&(state->strm));
567 free(state->out);
569 free(state->in);
571 gz_error(state, Z_OK, NULL);
572 free(state->path);
573 if (close(state->fd) == -1)
575 free(state);