Home | History | Annotate | Download | only in zlib

Lines Matching full: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 state->out = malloc(state->want);
24 if (state->in == NULL || state->out == NULL) {
25 if (state->out != NULL)
26 free(state->out);
27 if (state->in != NULL)
28 free(state->in);
29 gz_error(state, Z_MEM_ERROR, "out of memory");
37 ret = deflateInit2(strm, state->level, Z_DEFLATED,
38 15 + 16, 8, state->strategy);
40 free(state->in);
41 gz_error(state, Z_MEM_ERROR, "out of memory");
45 /* mark state as initialized */
46 state->size = state->want;
49 strm->avail_out = state->size;
50 strm->next_out = state->out;
51 state->next = strm->next_out;
58 then the deflate() state is reset to start a new gzip stream. */
59 local int gz_comp(state, flush)
60 gz_statep state;
65 z_streamp strm = &(state->strm);
68 if (state->size == 0 && gz_init(state) == -1)
78 have = (unsigned)(strm->next_out - state->next);
79 if (have && ((got = write(state->fd, state->next, have)) < 0 ||
81 gz_error(state, Z_ERRNO, zstrerror());
85 strm->avail_out = state->size;
86 strm->next_out = state->out;
88 state->next = strm->next_out;
95 gz_error(state, Z_STREAM_ERROR,
111 local int gz_zero(state, len)
112 gz_statep state;
117 z_streamp strm = &(state->strm);
120 if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
126 n = GT_OFF(state->size) || (z_off64_t)state->size > len ?
127 (unsigned)len : state->size;
129 memset(state->in, 0, n);
133 strm->next_in = state->in;
134 state->pos += n;
135 if (gz_comp(state, Z_NO_FLUSH) == -1)
150 gz_statep state;
156 state = (gz_statep)file;
157 strm = &(state->strm);
160 if (state->mode != GZ_WRITE || state->err != Z_OK)
166 gz_error(state, Z_BUF_ERROR, "requested length does not fit in int");
175 if (state->size == 0 && gz_init(state) == -1)
179 if (state->seek) {
180 state->seek = 0;
181 if (gz_zero(state, state->skip) == -1)
186 if (len < state->size) {
190 strm->next_in = state->in;
191 n = state->size - strm->avail_in;
196 state->pos += n;
199 if (len && gz_comp(state, Z_NO_FLUSH) == -1)
205 if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
211 state->pos += len;
212 if (gz_comp(state, Z_NO_FLUSH) == -1)
226 gz_statep state;
232 state = (gz_statep)file;
233 strm = &(state->strm);
236 if (state->mode != GZ_WRITE || state->err != Z_OK)
240 if (state->seek) {
241 state->seek = 0;
242 if (gz_zero(state, state->skip) == -1)
246 /* try writing to input buffer for speed (state->size == 0 if buffer not
248 if (strm->avail_in < state->size) {
250 strm->next_in = state->in;
252 state->pos++;
284 gz_statep state;
291 state = (gz_statep)file;
292 strm = &(state->strm);
295 if (state->mode != GZ_WRITE || state->err != Z_OK)
299 if (state->size == 0 && gz_init(state) == -1)
303 if (state->seek) {
304 state->seek = 0;
305 if (gz_zero(state, state->skip) == -1)
310 if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
314 size = (int)(state->size);
315 state->in[size - 1] = 0;
319 (void)vsprintf(state->in, format, va);
322 if (state->in[len] == 0) break;
324 len = vsprintf(state->in, format, va);
329 (void)vsnprintf(state->in, size, format, va);
331 len = strlen(state->in);
333 len = vsnprintf((char *)(state->in), size, format, va);
339 if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
344 strm->next_in = state->in;
345 state->pos += len;
360 gz_statep state;
366 state = (gz_statep)file;
367 strm = &(state->strm);
370 if (state->mode != GZ_WRITE || state->err != Z_OK)
374 if (state->size == 0 && gz_init(state) == -1)
378 if (state->seek) {
379 state->seek = 0;
380 if (gz_zero(state, state->skip) == -1)
385 if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
389 size = (int)(state->size);
390 state->in[size - 1] = 0;
393 sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8,
396 if (state->in[len] == 0) break;
398 len = sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8,
403 snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8,
405 len = strlen(state->in);
407 len = snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8,
413 if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
418 strm->next_in = state->in;
419 state->pos += len;
430 gz_statep state;
435 state = (gz_statep)file;
438 if (state->mode != GZ_WRITE || state->err != Z_OK)
446 if (state->seek) {
447 state->seek = 0;
448 if (gz_zero(state, state->skip) == -1)
453 gz_comp(state, flush);
454 return state->err;
463 gz_statep state;
469 state = (gz_statep)file;
470 strm = &(state->strm);
473 if (state->mode != GZ_WRITE || state->err != Z_OK)
477 if (level == state->level && strategy == state->strategy)
481 if (state->seek) {
482 state->seek = 0;
483 if (gz_zero(state, state->skip) == -1)
488 if (state->size) {
490 if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1)
491 return state->err;
494 state->level = level;
495 state->strategy = strategy;
504 gz_statep state;
509 state = (gz_statep)file;
512 if (state->mode != GZ_WRITE)
516 if (state->seek) {
517 state->seek = 0;
518 ret += gz_zero(state, state->skip);
522 ret += gz_comp(state, Z_FINISH);
523 (void)deflateEnd(&(state->strm));
524 free(state->out);
525 free(state->in);
526 gz_error(state, Z_OK, NULL);
527 free(state->path);
528 ret += close(state->fd);
529 free(state);