Fixed #1799 (linking issue) - use of VS only functions that were not

enclosed on #ifdef (not an issue with default link options, since the
functions using the VS only functions are not actually used in STK).
This commit is contained in:
hiker 2014-12-18 16:51:08 +11:00
parent 0af3f3de83
commit 6a806470f1
4 changed files with 590 additions and 4 deletions

View File

@ -234,9 +234,10 @@ local gzFile gz_open(path, fd, mode)
/* open the file with the appropriate flags (or just use fd) */
state->fd = fd > -1 ? fd : (
#ifdef _WIN32
fd == -2 ? _wopen(path, oflag, 0666) :
fd == -2 ? _wopen(path, oflag, 0666) : _open(path, oflag, 0666));
#else
open(path, oflag, 0666));
#endif
_open(path, oflag, 0666));
if (state->fd == -1) {
free(state->path);
free(state);

View File

@ -27,7 +27,11 @@ local int gz_load(state, buf, len, have)
*have = 0;
do {
#ifdef _WIN32
ret = _read(state->fd, buf + *have, len - *have);
#else
ret = read(state->fd, buf + *have, len - *have);
#endif
if (ret <= 0)
break;
*have += ret;
@ -583,7 +587,11 @@ int ZEXPORT gzclose_r(file)
err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
gz_error(state, Z_OK, NULL);
free(state->path);
#ifdef _WIN32
ret = _close(state->fd);
#else
ret = close(state->fd);
#endif
free(state);
return ret ? Z_ERRNO : err;
}

View File

@ -81,7 +81,11 @@ local int gz_comp(state, flush)
/* write directly if requested */
if (state->direct) {
#ifdef _WIN32
got = _write(state->fd, strm->next_in, strm->avail_in);
#else
got = write(state->fd, strm->next_in, strm->avail_in);
#endif
if (got < 0 || (unsigned)got != strm->avail_in) {
gz_error(state, Z_ERRNO, zstrerror());
return -1;
@ -98,8 +102,12 @@ local int gz_comp(state, flush)
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
(flush != Z_FINISH || ret == Z_STREAM_END))) {
have = (unsigned)(strm->next_out - state->x.next);
#ifdef _WIN32
if (have && ((got = _write(state->fd, state->x.next, have)) < 0 ||
(unsigned)got != have)) {
#else
if (have && ((got = write(state->fd, state->x.next, have)) < 0 ||
#endif
(unsigned)got != have)) {
gz_error(state, Z_ERRNO, zstrerror());
return -1;
}
@ -558,8 +566,12 @@ int ZEXPORT gzclose_w(file)
}
gz_error(state, Z_OK, NULL);
free(state->path);
#ifdef _WIN32
if (_close(state->fd) == -1)
ret = Z_ERRNO;
#else
if (_close(state->fd) == -1)
#endif
ret = Z_ERRNO;
free(state);
return ret;
}

View File

@ -0,0 +1,565 @@
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 1) /* gzwrite.c -- zlib functions for writing gzip files
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 2) * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 3) * For conditions of distribution and use, see copyright notice in zlib.h
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 4) */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 5)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 6) #include "gzguts.h"
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 7)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 8) /* Local functions */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 9) local int gz_init OF((gz_statep));
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 10) local int gz_comp OF((gz_statep, int));
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 11) local int gz_zero OF((gz_statep, z_off64_t));
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 12)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 13) /* Initialize state for writing a gzip file. Mark initialization by setting
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 14) state->size to non-zero. Return -1 on failure or 0 on success. */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 15) local int gz_init(state)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 16) gz_statep state;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 17) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 18) int ret;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 19) z_streamp strm = &(state->strm);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 20)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 21) /* allocate input buffer */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 22) state->in = malloc(state->want);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 23) if (state->in == NULL) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 24) gz_error(state, Z_MEM_ERROR, "out of memory");
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 25) return -1;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 26) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 27)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 28) /* only need output buffer and deflate state if compressing */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 29) if (!state->direct) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 30) /* allocate output buffer */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 31) state->out = malloc(state->want);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 32) if (state->out == NULL) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 33) free(state->in);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 34) gz_error(state, Z_MEM_ERROR, "out of memory");
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 35) return -1;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 36) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 37)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 38) /* allocate deflate memory, set up for gzip compression */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 39) strm->zalloc = Z_NULL;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 40) strm->zfree = Z_NULL;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 41) strm->opaque = Z_NULL;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 42) ret = deflateInit2(strm, state->level, Z_DEFLATED,
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 43) MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 44) if (ret != Z_OK) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 45) free(state->out);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 46) free(state->in);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 47) gz_error(state, Z_MEM_ERROR, "out of memory");
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 48) return -1;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 49) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 50) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 51)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 52) /* mark state as initialized */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 53) state->size = state->want;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 54)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 55) /* initialize write buffer if compressing */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 56) if (!state->direct) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 57) strm->avail_out = state->size;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 58) strm->next_out = state->out;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 59) state->x.next = strm->next_out;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 60) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 61) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 62) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 63)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 64) /* Compress whatever is at avail_in and next_in and write to the output file.
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 65) Return -1 if there is an error writing to the output file, otherwise 0.
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 66) flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH,
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 67) then the deflate() state is reset to start a new gzip stream. If gz->direct
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 68) is true, then simply write to the output file without compressing, and
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 69) ignore flush. */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 70) local int gz_comp(state, flush)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 71) gz_statep state;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 72) int flush;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 73) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 74) int ret, got;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 75) unsigned have;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 76) z_streamp strm = &(state->strm);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 77)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 78) /* allocate memory if this is the first time through */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 79) if (state->size == 0 && gz_init(state) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 80) return -1;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 81)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 82) /* write directly if requested */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 83) if (state->direct) {
d95f7835 (Timothy Hamlett 2014-11-30 22:29:52 -0600 84) got = _write(state->fd, strm->next_in, strm->avail_in);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 85) if (got < 0 || (unsigned)got != strm->avail_in) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 86) gz_error(state, Z_ERRNO, zstrerror());
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 87) return -1;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 88) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 89) strm->avail_in = 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 90) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 91) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 92)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 93) /* run deflate() on provided input until it produces no more output */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 94) ret = Z_OK;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 95) do {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 96) /* write out current buffer contents if full, or if flushing, but if
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 97) doing Z_FINISH then don't write until we get to Z_STREAM_END */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 98) if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 99) (flush != Z_FINISH || ret == Z_STREAM_END))) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 100) have = (unsigned)(strm->next_out - state->x.next);
d95f7835 (Timothy Hamlett 2014-11-30 22:29:52 -0600 101) if (have && ((got = _write(state->fd, state->x.next, have)) < 0 ||
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 102) (unsigned)got != have)) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 103) gz_error(state, Z_ERRNO, zstrerror());
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 104) return -1;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 105) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 106) if (strm->avail_out == 0) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 107) strm->avail_out = state->size;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 108) strm->next_out = state->out;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 109) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 110) state->x.next = strm->next_out;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 111) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 112)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 113) /* compress */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 114) have = strm->avail_out;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 115) ret = deflate(strm, flush);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 116) if (ret == Z_STREAM_ERROR) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 117) gz_error(state, Z_STREAM_ERROR,
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 118) "internal error: deflate stream corrupt");
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 119) return -1;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 120) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 121) have -= strm->avail_out;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 122) } while (have);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 123)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 124) /* if that completed a deflate stream, allow another to start */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 125) if (flush == Z_FINISH)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 126) deflateReset(strm);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 127)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 128) /* all done, no errors */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 129) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 130) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 131)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 132) /* Compress len zeros to output. Return -1 on error, 0 on success. */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 133) local int gz_zero(state, len)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 134) gz_statep state;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 135) z_off64_t len;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 136) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 137) int first;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 138) unsigned n;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 139) z_streamp strm = &(state->strm);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 140)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 141) /* consume whatever's left in the input buffer */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 142) if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 143) return -1;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 144)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 145) /* compress len zeros (len guaranteed > 0) */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 146) first = 1;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 147) while (len) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 148) n = GT_OFF(state->size) || (z_off64_t)state->size > len ?
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 149) (unsigned)len : state->size;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 150) if (first) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 151) memset(state->in, 0, n);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 152) first = 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 153) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 154) strm->avail_in = n;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 155) strm->next_in = state->in;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 156) state->x.pos += n;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 157) if (gz_comp(state, Z_NO_FLUSH) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 158) return -1;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 159) len -= n;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 160) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 161) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 162) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 163)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 164) /* -- see zlib.h -- */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 165) int ZEXPORT gzwrite(file, buf, len)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 166) gzFile file;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 167) voidpc buf;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 168) unsigned len;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 169) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 170) unsigned put = len;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 171) unsigned n;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 172) gz_statep state;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 173) z_streamp strm;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 174)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 175) /* get internal structure */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 176) if (file == NULL)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 177) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 178) state = (gz_statep)file;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 179) strm = &(state->strm);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 180)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 181) /* check that we're writing and that there's no error */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 182) if (state->mode != GZ_WRITE || state->err != Z_OK)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 183) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 184)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 185) /* since an int is returned, make sure len fits in one, otherwise return
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 186) with an error (this avoids the flaw in the interface) */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 187) if ((int)len < 0) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 188) gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 189) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 190) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 191)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 192) /* if len is zero, avoid unnecessary operations */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 193) if (len == 0)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 194) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 195)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 196) /* allocate memory if this is the first time through */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 197) if (state->size == 0 && gz_init(state) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 198) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 199)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 200) /* check for seek request */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 201) if (state->seek) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 202) state->seek = 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 203) if (gz_zero(state, state->skip) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 204) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 205) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 206)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 207) /* for small len, copy to input buffer, otherwise compress directly */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 208) if (len < state->size) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 209) /* copy to input buffer, compress when full */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 210) do {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 211) if (strm->avail_in == 0)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 212) strm->next_in = state->in;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 213) n = state->size - strm->avail_in;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 214) if (n > len)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 215) n = len;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 216) memcpy(strm->next_in + strm->avail_in, buf, n);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 217) strm->avail_in += n;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 218) state->x.pos += n;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 219) buf = (char *)buf + n;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 220) len -= n;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 221) if (len && gz_comp(state, Z_NO_FLUSH) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 222) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 223) } while (len);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 224) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 225) else {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 226) /* consume whatever's left in the input buffer */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 227) if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 228) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 229)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 230) /* directly compress user buffer to file */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 231) strm->avail_in = len;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 232) strm->next_in = (voidp)buf;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 233) state->x.pos += len;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 234) if (gz_comp(state, Z_NO_FLUSH) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 235) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 236) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 237)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 238) /* input was all buffered or compressed (put will fit in int) */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 239) return (int)put;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 240) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 241)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 242) /* -- see zlib.h -- */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 243) int ZEXPORT gzputc(file, c)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 244) gzFile file;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 245) int c;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 246) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 247) unsigned char buf[1];
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 248) gz_statep state;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 249) z_streamp strm;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 250)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 251) /* get internal structure */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 252) if (file == NULL)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 253) return -1;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 254) state = (gz_statep)file;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 255) strm = &(state->strm);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 256)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 257) /* check that we're writing and that there's no error */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 258) if (state->mode != GZ_WRITE || state->err != Z_OK)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 259) return -1;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 260)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 261) /* check for seek request */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 262) if (state->seek) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 263) state->seek = 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 264) if (gz_zero(state, state->skip) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 265) return -1;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 266) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 267)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 268) /* try writing to input buffer for speed (state->size == 0 if buffer not
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 269) initialized) */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 270) if (strm->avail_in < state->size) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 271) if (strm->avail_in == 0)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 272) strm->next_in = state->in;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 273) strm->next_in[strm->avail_in++] = c;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 274) state->x.pos++;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 275) return c & 0xff;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 276) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 277)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 278) /* no room in buffer or not initialized, use gz_write() */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 279) buf[0] = c;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 280) if (gzwrite(file, buf, 1) != 1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 281) return -1;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 282) return c & 0xff;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 283) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 284)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 285) /* -- see zlib.h -- */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 286) int ZEXPORT gzputs(file, str)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 287) gzFile file;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 288) const char *str;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 289) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 290) int ret;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 291) unsigned len;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 292)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 293) /* write string */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 294) len = (unsigned)strlen(str);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 295) ret = gzwrite(file, str, len);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 296) return ret == 0 && len != 0 ? -1 : ret;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 297) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 298)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 299) #if defined(STDC) || defined(Z_HAVE_STDARG_H)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 300) #include <stdarg.h>
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 301)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 302) /* -- see zlib.h -- */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 303) int ZEXPORTVA gzprintf (gzFile file, const char *format, ...)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 304) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 305) int size, len;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 306) gz_statep state;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 307) z_streamp strm;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 308) va_list va;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 309)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 310) /* get internal structure */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 311) if (file == NULL)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 312) return -1;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 313) state = (gz_statep)file;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 314) strm = &(state->strm);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 315)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 316) /* check that we're writing and that there's no error */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 317) if (state->mode != GZ_WRITE || state->err != Z_OK)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 318) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 319)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 320) /* make sure we have some buffer space */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 321) if (state->size == 0 && gz_init(state) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 322) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 323)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 324) /* check for seek request */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 325) if (state->seek) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 326) state->seek = 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 327) if (gz_zero(state, state->skip) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 328) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 329) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 330)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 331) /* consume whatever's left in the input buffer */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 332) if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 333) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 334)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 335) /* do the printf() into the input buffer, put length in len */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 336) size = (int)(state->size);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 337) state->in[size - 1] = 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 338) va_start(va, format);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 339) #ifdef NO_vsnprintf
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 340) # ifdef HAS_vsprintf_void
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 341) (void)vsprintf((char *)(state->in), format, va);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 342) va_end(va);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 343) for (len = 0; len < size; len++)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 344) if (state->in[len] == 0) break;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 345) # else
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 346) len = vsprintf((char *)(state->in), format, va);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 347) va_end(va);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 348) # endif
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 349) #else
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 350) # ifdef HAS_vsnprintf_void
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 351) (void)vsnprintf((char *)(state->in), size, format, va);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 352) va_end(va);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 353) len = strlen((char *)(state->in));
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 354) # else
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 355) len = vsnprintf((char *)(state->in), size, format, va);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 356) va_end(va);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 357) # endif
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 358) #endif
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 359)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 360) /* check that printf() results fit in buffer */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 361) if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 362) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 363)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 364) /* update buffer and position, defer compression until needed */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 365) strm->avail_in = (unsigned)len;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 366) strm->next_in = state->in;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 367) state->x.pos += len;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 368) return len;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 369) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 370)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 371) #else /* !STDC && !Z_HAVE_STDARG_H */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 372)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 373) /* -- see zlib.h -- */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 374) int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 375) a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 376) gzFile file;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 377) const char *format;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 378) int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 379) a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 380) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 381) int size, len;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 382) gz_statep state;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 383) z_streamp strm;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 384)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 385) /* get internal structure */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 386) if (file == NULL)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 387) return -1;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 388) state = (gz_statep)file;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 389) strm = &(state->strm);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 390)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 391) /* check that can really pass pointer in ints */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 392) if (sizeof(int) != sizeof(void *))
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 393) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 394)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 395) /* check that we're writing and that there's no error */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 396) if (state->mode != GZ_WRITE || state->err != Z_OK)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 397) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 398)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 399) /* make sure we have some buffer space */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 400) if (state->size == 0 && gz_init(state) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 401) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 402)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 403) /* check for seek request */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 404) if (state->seek) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 405) state->seek = 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 406) if (gz_zero(state, state->skip) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 407) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 408) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 409)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 410) /* consume whatever's left in the input buffer */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 411) if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 412) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 413)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 414) /* do the printf() into the input buffer, put length in len */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 415) size = (int)(state->size);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 416) state->in[size - 1] = 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 417) #ifdef NO_snprintf
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 418) # ifdef HAS_sprintf_void
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 419) sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 420) a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 421) for (len = 0; len < size; len++)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 422) if (state->in[len] == 0) break;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 423) # else
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 424) len = sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 425) a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 426) # endif
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 427) #else
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 428) # ifdef HAS_snprintf_void
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 429) snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, a7, a8,
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 430) a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 431) len = strlen((char *)(state->in));
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 432) # else
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 433) len = snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6,
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 434) a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18,
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 435) a19, a20);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 436) # endif
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 437) #endif
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 438)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 439) /* check that printf() results fit in buffer */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 440) if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 441) return 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 442)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 443) /* update buffer and position, defer compression until needed */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 444) strm->avail_in = (unsigned)len;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 445) strm->next_in = state->in;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 446) state->x.pos += len;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 447) return len;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 448) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 449)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 450) #endif
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 451)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 452) /* -- see zlib.h -- */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 453) int ZEXPORT gzflush(file, flush)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 454) gzFile file;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 455) int flush;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 456) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 457) gz_statep state;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 458)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 459) /* get internal structure */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 460) if (file == NULL)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 461) return -1;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 462) state = (gz_statep)file;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 463)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 464) /* check that we're writing and that there's no error */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 465) if (state->mode != GZ_WRITE || state->err != Z_OK)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 466) return Z_STREAM_ERROR;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 467)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 468) /* check flush parameter */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 469) if (flush < 0 || flush > Z_FINISH)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 470) return Z_STREAM_ERROR;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 471)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 472) /* check for seek request */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 473) if (state->seek) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 474) state->seek = 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 475) if (gz_zero(state, state->skip) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 476) return -1;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 477) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 478)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 479) /* compress remaining data with requested flush */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 480) gz_comp(state, flush);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 481) return state->err;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 482) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 483)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 484) /* -- see zlib.h -- */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 485) int ZEXPORT gzsetparams(file, level, strategy)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 486) gzFile file;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 487) int level;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 488) int strategy;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 489) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 490) gz_statep state;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 491) z_streamp strm;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 492)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 493) /* get internal structure */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 494) if (file == NULL)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 495) return Z_STREAM_ERROR;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 496) state = (gz_statep)file;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 497) strm = &(state->strm);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 498)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 499) /* check that we're writing and that there's no error */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 500) if (state->mode != GZ_WRITE || state->err != Z_OK)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 501) return Z_STREAM_ERROR;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 502)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 503) /* if no change is requested, then do nothing */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 504) if (level == state->level && strategy == state->strategy)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 505) return Z_OK;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 506)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 507) /* check for seek request */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 508) if (state->seek) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 509) state->seek = 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 510) if (gz_zero(state, state->skip) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 511) return -1;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 512) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 513)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 514) /* change compression parameters for subsequent input */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 515) if (state->size) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 516) /* flush previous input with previous parameters before changing */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 517) if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 518) return state->err;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 519) deflateParams(strm, level, strategy);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 520) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 521) state->level = level;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 522) state->strategy = strategy;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 523) return Z_OK;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 524) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 525)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 526) /* -- see zlib.h -- */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 527) int ZEXPORT gzclose_w(file)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 528) gzFile file;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 529) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 530) int ret = Z_OK;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 531) gz_statep state;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 532)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 533) /* get internal structure */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 534) if (file == NULL)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 535) return Z_STREAM_ERROR;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 536) state = (gz_statep)file;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 537)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 538) /* check that we're writing */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 539) if (state->mode != GZ_WRITE)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 540) return Z_STREAM_ERROR;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 541)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 542) /* check for seek request */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 543) if (state->seek) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 544) state->seek = 0;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 545) if (gz_zero(state, state->skip) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 546) ret = state->err;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 547) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 548)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 549) /* flush, free memory, and close file */
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 550) if (state->size) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 551) if (gz_comp(state, Z_FINISH) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 552) ret = state->err;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 553) if (!state->direct) {
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 554) (void)deflateEnd(&(state->strm));
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 555) free(state->out);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 556) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 557) free(state->in);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 558) }
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 559) gz_error(state, Z_OK, NULL);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 560) free(state->path);
d95f7835 (Timothy Hamlett 2014-11-30 22:29:52 -0600 561) if (_close(state->fd) == -1)
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 562) ret = Z_ERRNO;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 563) free(state);
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 564) return ret;
974deca5 (hikerstk 2012-11-01 02:00:02 +0000 565) }