24 state->in = (
unsigned char *)malloc(state->want << 1);
25 if (state->in == NULL) {
33 state->out = (
unsigned char *)malloc(state->want);
34 if (state->out == NULL) {
56 state->size = state->want;
60 strm->avail_out = state->size;
61 strm->next_out = state->out;
62 state->x.next = strm->next_out;
78 unsigned have, put,
max = ((unsigned)-1 >> 2) + 1;
82 if (state->size == 0 &&
gz_init(state) == -1)
87 while (strm->avail_in) {
88 put = strm->avail_in > max ? max : strm->avail_in;
89 writ = write(state->fd, strm->next_in, put);
94 strm->avail_in -= (unsigned)writ;
95 strm->next_in += writ;
105 if (strm->avail_out == 0 || (flush !=
Z_NO_FLUSH &&
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);
115 state->x.next += writ;
117 if (strm->avail_out == 0) {
118 strm->avail_out = state->size;
119 strm->next_out = state->out;
120 state->x.next = state->out;
125 have = strm->avail_out;
129 "internal error: deflate stream corrupt");
132 have -= strm->avail_out;
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;
190 if (state->size == 0 &&
gz_init(state) == -1)
196 if (
gz_zero(state, state->skip) == -1)
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) -
210 copy = state->size - have;
212 copy = (unsigned)len;
213 memcpy(state->in + have, buf, copy);
214 state->strm.avail_in +=
copy;
215 state->x.pos +=
copy;
216 buf = (
const char *)buf + copy;
228 state->strm.next_in = (z_const Bytef *)buf;
230 unsigned n = (unsigned)-1;
233 state->strm.avail_in =
n;
270 return (
int)
gz_write(state, buf, len);
294 if (size && len / size != nitems) {
300 return len ?
gz_write(state, buf, len) / size : 0;
309 unsigned char buf[1];
317 strm = &(state->strm);
326 if (
gz_zero(state, state->skip) == -1)
333 if (strm->avail_in == 0)
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;
345 buf[0] = (
unsigned char)c;
378 return ret < (
int)len ? -1 : ret;
381 #if defined(STDC) || defined(Z_HAVE_STDARG_H)
385 int ZEXPORTVA gzvprintf(
gzFile file,
const char *format, va_list va)
397 strm = &(state->strm);
404 if (state->size == 0 &&
gz_init(state) == -1)
410 if (
gz_zero(state, state->skip) == -1)
417 if (strm->avail_in == 0)
418 strm->next_in = state->in;
419 next = (
char *)(state->in + (strm->next_in - state->in) + strm->avail_in);
420 next[state->size - 1] = 0;
422 # ifdef HAS_vsprintf_void
423 (
void)vsprintf(next, format, va);
424 for (len = 0; len < state->size; len++)
425 if (next[len] == 0)
break;
427 len = vsprintf(next, format, va);
430 # ifdef HAS_vsnprintf_void
431 (
void)vsnprintf(next, state->size, format, va);
434 len = vsnprintf(next, state->size, format, va);
439 if (len == 0 || (
unsigned)len >= state->size || next[state->size - 1] != 0)
443 strm->avail_in += (unsigned)len;
445 if (strm->avail_in >= state->size) {
446 left = strm->avail_in - state->size;
447 strm->avail_in = state->size;
450 memcpy(state->in, state->in + state->size, left);
451 strm->next_in = state->in;
452 strm->avail_in =
left;
462 va_start(va, format);
463 ret = gzvprintf(file, format, va);
471 int ZEXPORTVA
gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
472 a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
475 int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
476 a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
487 strm = &(state->strm);
490 if (
sizeof(
int) !=
sizeof(
void *))
498 if (state->size == 0 &&
gz_init(state) == -1)
504 if (
gz_zero(state, state->skip) == -1)
511 if (strm->avail_in == 0)
512 strm->next_in = state->in;
513 next = (
char *)(strm->next_in + strm->avail_in);
514 next[state->size - 1] = 0;
516 # ifdef HAS_sprintf_void
517 sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12,
518 a13, a14, a15, a16, a17, a18, a19, a20);
519 for (len = 0; len < size; len++)
523 len = sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,
524 a12, a13, a14, a15, a16, a17, a18, a19, a20);
527 # ifdef HAS_snprintf_void
528 snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8, a9,
529 a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
532 len = snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8,
533 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
538 if (len == 0 || len >= state->size || next[state->size - 1] != 0)
542 strm->avail_in +=
len;
544 if (strm->avail_in >= state->size) {
545 left = strm->avail_in - state->size;
546 strm->avail_in = state->size;
549 memcpy(state->in, state->in + state->size, left);
550 strm->next_in = state->in;
551 strm->avail_in =
left;
581 if (
gz_zero(state, state->skip) == -1)
603 strm = &(state->strm);
610 if (level == state->level && strategy == state->strategy)
616 if (
gz_zero(state, state->skip) == -1)
627 state->level =
level;
651 if (
gz_zero(state, state->skip) == -1)
659 if (!state->direct) {
667 if (
close(state->fd) == -1)