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)
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) -
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;
377 ret = (int)
gz_write(state, str, len);
378 return ret < (int)len ? -1 : ret;
381#if defined(STDC) || defined(Z_HAVE_STDARG_H)
385int 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);
471int 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;
628 state->strategy = strategy;
651 if (
gz_zero(state, state->skip) == -1)
659 if (!state->direct) {
667 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 gzputs(gzFile file, const char *str)
int ZEXPORT gzputc(gzFile file, int c)
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))