18     z_streamp strm = &(state->strm);
 
   21     state->in = (
unsigned char *)
malloc(state->want);
 
   22     if (state->in == NULL) {
 
   23         gz_error(state, Z_MEM_ERROR, 
"out of memory");
 
   30         state->out = (
unsigned char *)
malloc(state->want);
 
   31         if (state->out == NULL) {
 
   33             gz_error(state, Z_MEM_ERROR, 
"out of memory");
 
   38         strm->zalloc = Z_NULL;
 
   40         strm->opaque = Z_NULL;
 
   41         ret = deflateInit2(strm, state->level, Z_DEFLATED,
 
   42                            MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
 
   46             gz_error(state, Z_MEM_ERROR, 
"out of memory");
 
   52     state->size = state->want;
 
   56         strm->avail_out = state->size;
 
   57         strm->next_out = state->out;
 
   58         state->x.next = strm->next_out;
 
   73     z_streamp strm = &(state->strm);
 
   76     if (state->size == 0 && 
gz_init(state) == -1)
 
   81         got = write(state->fd, strm->next_in, strm->avail_in);
 
   82         if (got < 0 || (
unsigned)got != strm->avail_in) {
 
   83             gz_error(state, Z_ERRNO, zstrerror());
 
   95         if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
 
   96             (flush != Z_FINISH || ret == Z_STREAM_END))) {
 
   97             have = (unsigned)(strm->next_out - state->x.next);
 
   98             if (have && ((got = write(state->fd, state->x.next, have)) < 0 ||
 
   99                          (
unsigned)got != have)) {
 
  100                 gz_error(state, Z_ERRNO, zstrerror());
 
  103             if (strm->avail_out == 0) {
 
  104                 strm->avail_out = state->size;
 
  105                 strm->next_out = state->out;
 
  107             state->x.next = strm->next_out;
 
  111         have = strm->avail_out;
 
  113         if (ret == Z_STREAM_ERROR) {
 
  115                       "internal error: deflate stream corrupt");
 
  118         have -= strm->avail_out;
 
  122     if (flush == Z_FINISH)
 
  134     z_streamp strm = &(state->strm);
 
  137     if (strm->avail_in && 
gz_comp(state, Z_NO_FLUSH) == -1)
 
  143         n = GT_OFF(state->size) || (z_off64_t)state->size > len ?
 
  144             (
unsigned)len : state->size;
 
  146             memset(state->in, 0, n);
 
  150         strm->next_in = state->in;
 
  152         if (
gz_comp(state, Z_NO_FLUSH) == -1)
 
  160 int ZEXPORT 
gzwrite(gzFile file, voidpc buf, 
unsigned len)
 
  170     state = (gz_statep)file;
 
  171     strm = &(state->strm);
 
  174     if (state->mode != GZ_WRITE || state->err != Z_OK)
 
  180         gz_error(state, Z_DATA_ERROR, 
"requested length does not fit in int");
 
  189     if (state->size == 0 && 
gz_init(state) == -1)
 
  195         if (
gz_zero(state, state->skip) == -1)
 
  200     if (len < state->size) {
 
  203             if (strm->avail_in == 0)
 
  204                 strm->next_in = state->in;
 
  205             n = state->size - strm->avail_in;
 
  208             memcpy(strm->next_in + strm->avail_in, buf, n);
 
  211             buf = (
char *)buf + n;
 
  213             if (len && 
gz_comp(state, Z_NO_FLUSH) == -1)
 
  219         if (strm->avail_in && 
gz_comp(state, Z_NO_FLUSH) == -1)
 
  223         strm->avail_in = len;
 
  224         strm->next_in = (z_const Bytef *)buf;
 
  226         if (
gz_comp(state, Z_NO_FLUSH) == -1)
 
  237     unsigned char buf[1];
 
  244     state = (gz_statep)file;
 
  245     strm = &(state->strm);
 
  248     if (state->mode != GZ_WRITE || state->err != Z_OK)
 
  254         if (
gz_zero(state, state->skip) == -1)
 
  260     if (strm->avail_in < state->size) {
 
  261         if (strm->avail_in == 0)
 
  262             strm->next_in = state->in;
 
  263         strm->next_in[strm->avail_in++] = c;
 
  270     if (
gzwrite(file, buf, 1) != 1)
 
  276 int ZEXPORT 
gzputs(gzFile file, 
const char *str)
 
  282     len = (unsigned)strlen(str);
 
  284     return ret == 0 && len != 0 ? -1 : ret;
 
  287 #if defined(STDC) || defined(Z_HAVE_STDARG_H) 
  291 int ZEXPORTVA 
gzprintf (gzFile file, 
const char *format, ...)
 
  301     state = (gz_statep)file;
 
  302     strm = &(state->strm);
 
  305     if (state->mode != GZ_WRITE || state->err != Z_OK)
 
  309     if (state->size == 0 && 
gz_init(state) == -1)
 
  315         if (
gz_zero(state, state->skip) == -1)
 
  320     if (strm->avail_in && 
gz_comp(state, Z_NO_FLUSH) == -1)
 
  324     size = (int)(state->size);
 
  325     state->in[size - 1] = 0;
 
  326     va_start(va, format);
 
  328 #  ifdef HAS_vsprintf_void 
  329     (void)vsprintf((
char *)(state->in), format, va);
 
  331     for (len = 0; len < size; len++)
 
  332         if (state->in[len] == 0) 
break;
 
  334     len = vsprintf((
char *)(state->in), format, va);
 
  338 #  ifdef HAS_vsnprintf_void 
  339     (void)vsnprintf((
char *)(state->in), size, format, va);
 
  341     len = strlen((
char *)(state->in));
 
  343     len = vsnprintf((
char *)(state->in), size, format, va);
 
  349     if (len <= 0 || len >= (
int)size || state->in[size - 1] != 0)
 
  353     strm->avail_in = (unsigned)len;
 
  354     strm->next_in = state->in;
 
  362 int ZEXPORTVA 
gzprintf (gzFile file, 
const char *format, 
 
  363            int a1, 
int a2, 
int a3, 
int a4, 
int a5, 
int a6, 
int a7, 
int a8, 
int a9, 
int a10,
 
  364            int a11, 
int a12, 
int a13, 
int a14, 
int a15, 
int a16, 
int a17, 
int a18, 
int a19, 
int a20)
 
  373     state = (gz_statep)file;
 
  374     strm = &(state->strm);
 
  377     if (
sizeof(
int) != 
sizeof(
void *))
 
  381     if (state->mode != GZ_WRITE || state->err != Z_OK)
 
  385     if (state->size == 0 && 
gz_init(state) == -1)
 
  391         if (
gz_zero(state, state->skip) == -1)
 
  396     if (strm->avail_in && 
gz_comp(state, Z_NO_FLUSH) == -1)
 
  400     size = (int)(state->size);
 
  401     state->in[size - 1] = 0;
 
  403 #  ifdef HAS_sprintf_void 
  404     sprintf((
char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
 
  405             a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
 
  406     for (len = 0; len < size; len++)
 
  407         if (state->in[len] == 0) 
break;
 
  409     len = sprintf((
char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
 
  410                   a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
 
  413 #  ifdef HAS_snprintf_void 
  414     snprintf((
char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, a7, a8,
 
  415              a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
 
  416     len = strlen((
char *)(state->in));
 
  418     len = snprintf((
char *)(state->in), size, format, a1, a2, a3, a4, a5, a6,
 
  419                    a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18,
 
  425     if (len <= 0 || len >= (
int)size || state->in[size - 1] != 0)
 
  429     strm->avail_in = (unsigned)len;
 
  430     strm->next_in = state->in;
 
  445     state = (gz_statep)file;
 
  448     if (state->mode != GZ_WRITE || state->err != Z_OK)
 
  449         return Z_STREAM_ERROR;
 
  452     if (flush < 0 || flush > Z_FINISH)
 
  453         return Z_STREAM_ERROR;
 
  458         if (
gz_zero(state, state->skip) == -1)
 
  475         return Z_STREAM_ERROR;
 
  476     state = (gz_statep)file;
 
  477     strm = &(state->strm);
 
  480     if (state->mode != GZ_WRITE || state->err != Z_OK)
 
  481         return Z_STREAM_ERROR;
 
  484     if (level == state->level && strategy == state->strategy)
 
  490         if (
gz_zero(state, state->skip) == -1)
 
  497         if (strm->avail_in && 
gz_comp(state, Z_PARTIAL_FLUSH) == -1)
 
  501     state->level = level;
 
  502     state->strategy = strategy;
 
  514         return Z_STREAM_ERROR;
 
  515     state = (gz_statep)file;
 
  518     if (state->mode != GZ_WRITE)
 
  519         return Z_STREAM_ERROR;
 
  524         if (
gz_zero(state, state->skip) == -1)
 
  530         if (
gz_comp(state, Z_FINISH) == -1)
 
  532         if (!state->direct) {
 
  540     if (close(state->fd) == -1)
 
int ZEXPORT deflateEnd(z_streamp strm)
 
void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
 
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 gzsetparams(gzFile file, int level, int strategy)
 
int ZEXPORT gzputs(gzFile file, const char *str)
 
local int gz_init OF((gz_statep))
 
int ZEXPORT deflateParams(z_streamp strm, int level, int strategy)
 
local int gz_comp(gz_statep state, int flush)
 
int ZEXPORT gzputc(gzFile file, int c)
 
int ZEXPORT gzclose_w(gzFile file)
 
int ZEXPORT deflate(z_streamp strm, int flush)
 
int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len)
 
void * malloc(size_t __size)
 
local int gz_init(gz_statep state)
 
int ZEXPORT deflateReset(z_streamp strm)
 
local int gz_zero(gz_statep state, z_off64_t len)
 
int ZEXPORT gzflush(gzFile file, int flush)