aboutsummaryrefslogtreecommitdiff
path: root/gzwrite.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2011-09-09 23:27:17 -0700
committerMark Adler <madler@alumni.caltech.edu>2011-09-09 23:27:17 -0700
commite0ff940e1adb68d3575705ebf1546d9f07ad3b4a (patch)
tree792ac6996d1225c0955027050296126bc8ff6e26 /gzwrite.c
parent7df877eccdd826e94df53215f65dee639428e83f (diff)
downloadzlib-e0ff940e1adb68d3575705ebf1546d9f07ad3b4a.tar.gz
zlib-e0ff940e1adb68d3575705ebf1546d9f07ad3b4a.tar.bz2
zlib-e0ff940e1adb68d3575705ebf1546d9f07ad3b4a.zip
zlib 1.2.3.8v1.2.3.8
Diffstat (limited to 'gzwrite.c')
-rw-r--r--gzwrite.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/gzwrite.c b/gzwrite.c
index f4a0a80..50b1a7c 100644
--- a/gzwrite.c
+++ b/gzwrite.c
@@ -10,7 +10,7 @@
10/* Local functions */ 10/* Local functions */
11local int gz_init OF((gz_statep)); 11local int gz_init OF((gz_statep));
12local int gz_comp OF((gz_statep, int)); 12local int gz_comp OF((gz_statep, int));
13local int gz_zero OF((gz_statep, z_off_t)); 13local int gz_zero OF((gz_statep, z_off64_t));
14 14
15/* Initialize state for writing a gzip file. Mark initialization by setting 15/* Initialize state for writing a gzip file. Mark initialization by setting
16 state->size to non-zero. Return -1 on failure or 0 on success. */ 16 state->size to non-zero. Return -1 on failure or 0 on success. */
@@ -62,7 +62,7 @@ local int gz_comp(state, flush)
62 gz_statep state; 62 gz_statep state;
63 int flush; 63 int flush;
64{ 64{
65 int ret; 65 int ret, got;
66 unsigned have; 66 unsigned have;
67 z_streamp strm = &(state->strm); 67 z_streamp strm = &(state->strm);
68 68
@@ -78,7 +78,8 @@ local int gz_comp(state, flush)
78 if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && 78 if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
79 (flush != Z_FINISH || ret == Z_STREAM_END))) { 79 (flush != Z_FINISH || ret == Z_STREAM_END))) {
80 have = strm->next_out - state->next; 80 have = strm->next_out - state->next;
81 if (have && write(state->fd, state->next, have) != have) { 81 if (have && ((got = write(state->fd, state->next, have)) < 0 ||
82 (unsigned)got != have)) {
82 gz_error(state, Z_ERRNO, zstrerror()); 83 gz_error(state, Z_ERRNO, zstrerror());
83 return -1; 84 return -1;
84 } 85 }
@@ -111,7 +112,7 @@ local int gz_comp(state, flush)
111/* Compress len zeros to output. Return -1 on error, 0 on success. */ 112/* Compress len zeros to output. Return -1 on error, 0 on success. */
112local int gz_zero(state, len) 113local int gz_zero(state, len)
113 gz_statep state; 114 gz_statep state;
114 z_off_t len; 115 z_off64_t len;
115{ 116{
116 int first; 117 int first;
117 unsigned n; 118 unsigned n;
@@ -121,10 +122,11 @@ local int gz_zero(state, len)
121 if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) 122 if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
122 return -1; 123 return -1;
123 124
124 /* compress len zeros */ 125 /* compress len zeros (len guaranteed > 0) */
125 first = 1; 126 first = 1;
126 while (len) { 127 while (len) {
127 n = len < state->size ? (unsigned)len : state->size; 128 n = GT_OFF(state->size) || (z_off64_t)state->size > len ?
129 (unsigned)len : state->size;
128 if (first) { 130 if (first) {
129 memset(state->in, 0, n); 131 memset(state->in, 0, n);
130 first = 0; 132 first = 0;
@@ -435,7 +437,8 @@ int ZEXPORT gzflush(file, flush)
435 state = (gz_statep)file; 437 state = (gz_statep)file;
436 438
437 /* check that we're writing and that there's no error */ 439 /* check that we're writing and that there's no error */
438 if (state->mode != GZ_WRITE|| state->err != Z_OK) 440 if (state->mode != GZ_WRITE || state->err != Z_OK)
441 return Z_STREAM_ERROR;
439 442
440 /* check flush parameter */ 443 /* check flush parameter */
441 if (flush < 0 || flush > Z_FINISH) 444 if (flush < 0 || flush > Z_FINISH)