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;
103 if (strm->avail_in == 0)
114 if (strm->avail_out == 0 || (flush !=
Z_NO_FLUSH &&
116 while (strm->next_out > state->x.next) {
117 put = strm->next_out - state->x.next > (int)max ? max :
118 (
unsigned)(strm->next_out - state->x.next);
119 writ = write(state->fd, state->x.next, put);
124 state->x.next += writ;
126 if (strm->avail_out == 0) {
127 strm->avail_out = state->size;
128 strm->next_out = state->out;
129 state->x.next = state->out;
134 have = strm->avail_out;
138 "internal error: deflate stream corrupt");
141 have -= strm->avail_out;
169 n =
GT_OFF(state->size) || (z_off64_t)state->size > len ?
170 (
unsigned)len : state->size;
172 memset(state->in, 0, n);
176 strm->next_in = state->in;
199 if (state->size == 0 &&
gz_init(state) == -1)
205 if (
gz_zero(state, state->skip) == -1)
210 if (len < state->size) {
215 if (state->strm.avail_in == 0)
216 state->strm.next_in = state->in;
217 have = (unsigned)((state->strm.next_in + state->strm.avail_in) -
219 copy = state->size - have;
221 copy = (unsigned)len;
222 memcpy(state->in + have, buf, copy);
223 state->strm.avail_in += copy;
224 state->x.pos += copy;
225 buf = (
const char *)buf + copy;
237 state->strm.next_in = (z_const Bytef *)buf;
239 unsigned n = (unsigned)-1;
242 state->strm.avail_in = n;
279 return (
int)
gz_write(state, buf, len);
303 if (size && len / size != nitems) {
309 return len ?
gz_write(state, buf, len) / size : 0;
318 unsigned char buf[1];
326 strm = &(state->strm);
335 if (
gz_zero(state, state->skip) == -1)
342 if (strm->avail_in == 0)
343 strm->next_in = state->in;
344 have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
345 if (have < state->size) {
346 state->in[have] = (
unsigned char)c;
354 buf[0] = (
unsigned char)c;
379 if ((
int)len < 0 || (
unsigned)len != len) {
384 return put < len ? -1 : (int)len;
387#if defined(STDC) || defined(Z_HAVE_STDARG_H)
391int ZEXPORTVA gzvprintf(
gzFile file,
const char *format, va_list va)
403 strm = &(state->strm);
410 if (state->size == 0 &&
gz_init(state) == -1)
416 if (
gz_zero(state, state->skip) == -1)
423 if (strm->avail_in == 0)
424 strm->next_in = state->in;
425 next = (
char *)(state->in + (strm->next_in - state->in) + strm->avail_in);
426 next[state->size - 1] = 0;
428# ifdef HAS_vsprintf_void
429 (void)vsprintf(next, format, va);
430 for (len = 0; len < state->size; len++)
431 if (next[len] == 0)
break;
433 len = vsprintf(next, format, va);
436# ifdef HAS_vsnprintf_void
437 (void)vsnprintf(next, state->size, format, va);
440 len = vsnprintf(next, state->size, format, va);
445 if (len == 0 || (
unsigned)len >= state->size || next[state->size - 1] != 0)
449 strm->avail_in += (unsigned)len;
451 if (strm->avail_in >= state->size) {
452 left = strm->avail_in - state->size;
453 strm->avail_in = state->size;
456 memmove(state->in, state->in + state->size, left);
457 strm->next_in = state->in;
458 strm->avail_in = left;
468 va_start(va, format);
469 ret = gzvprintf(file, format, va);
477int ZEXPORTVA
gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
478 a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
481 int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
482 a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
493 strm = &(state->strm);
496 if (
sizeof(
int) !=
sizeof(
void *))
504 if (state->size == 0 &&
gz_init(state) == -1)
510 if (
gz_zero(state, state->skip) == -1)
517 if (strm->avail_in == 0)
518 strm->next_in = state->in;
519 next = (
char *)(strm->next_in + strm->avail_in);
520 next[state->size - 1] = 0;
522# ifdef HAS_sprintf_void
523 sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12,
524 a13, a14, a15, a16, a17, a18, a19, a20);
525 for (len = 0; len < size; len++)
529 len = sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,
530 a12, a13, a14, a15, a16, a17, a18, a19, a20);
533# ifdef HAS_snprintf_void
534 snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8, a9,
535 a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
538 len = snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8,
539 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
544 if (len == 0 || len >= state->size || next[state->size - 1] != 0)
548 strm->avail_in += len;
550 if (strm->avail_in >= state->size) {
551 left = strm->avail_in - state->size;
552 strm->avail_in = state->size;
555 memmove(state->in, state->in + state->size, left);
556 strm->next_in = state->in;
557 strm->avail_in = left;
587 if (
gz_zero(state, state->skip) == -1)
609 strm = &(state->strm);
616 if (level == state->level && strategy == state->strategy)
622 if (
gz_zero(state, state->skip) == -1)
633 state->level = level;
634 state->strategy = strategy;
657 if (
gz_zero(state, state->skip) == -1)
665 if (!state->direct) {
673 if (close(state->fd) == -1)
int ZEXPORT deflateReset(z_streamp strm)
int ZEXPORT deflateParams(z_streamp strm, int level, int strategy)
int ZEXPORT deflateEnd(z_streamp strm)
int ZEXPORT deflate(z_streamp strm, int flush)
void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
int ZEXPORT gzsetparams(gzFile file, int level, int strategy)
int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20)
int ZEXPORT gzputc(gzFile file, int c)
int ZEXPORT gzputs(gzFile file, const char *s)
int gz_comp(gz_statep state, int flush)
int ZEXPORT gzflush(gzFile file, int flush)
int ZEXPORT gzclose_w(gzFile file)
int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len)
z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len)
z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, z_size_t nitems, gzFile file)
int gz_init(gz_statep state)
int gz_zero(gz_statep state, z_off64_t len)
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy)
voidpf alloc_func OF((voidpf opaque, uInt items, uInt size))