summaryrefslogtreecommitdiff
path: root/gzwrite.c
diff options
context:
space:
mode:
authorHans Kristian Rosbach <hk-git@circlestorm.org>2017-01-30 13:41:41 +0100
committerHans Kristian Rosbach <hk-git@circlestorm.org>2017-01-30 13:41:41 +0100
commit450b53683c60243687c52aabf595a0e0951c93ac (patch)
treee93bb70a6a54c61b25578782961b95cb6e58988a /gzwrite.c
parent317e8824c90445366e156a61d7bf57631169e30e (diff)
Revert "Loop on write() calls in gzwrite.c in case of non-blocking I/O."
This reverts commit 4811aa74806df01ac7e5a28c7a6b42bc6795b7a4. Reverted because the code returns incorrect data. Needs to be investigated and re-implemented.
Diffstat (limited to 'gzwrite.c')
-rw-r--r--gzwrite.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/gzwrite.c b/gzwrite.c
index 6ef2242..f84ec18 100644
--- a/gzwrite.c
+++ b/gzwrite.c
@@ -77,14 +77,12 @@ static int gz_comp(gz_statep state, int flush) {
/* write directly if requested */
if (state->direct) {
- while (strm->avail_in) {
- if ((got = write(state->fd, strm->next_in, strm->avail_in)) < 0) {
- gz_error(state, Z_ERRNO, zstrerror());
- return -1;
- }
- strm->avail_in -= got;
- strm->next_in += got;
+ got = write(state->fd, strm->next_in, strm->avail_in);
+ if (got < 0 || (unsigned)got != strm->avail_in) {
+ gz_error(state, Z_ERRNO, zstrerror());
+ return -1;
}
+ strm->avail_in = 0;
return 0;
}
@@ -94,17 +92,16 @@ static int gz_comp(gz_statep state, int flush) {
/* write out current buffer contents if full, or if flushing, but if
doing Z_FINISH then don't write until we get to Z_STREAM_END */
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && (flush != Z_FINISH || ret == Z_STREAM_END))) {
- while (strm->next_out > state->x.next) {
- if ((got = write(state->fd, state->x.next, strm->next_out - state->x.next)) < 0) {
- gz_error(state, Z_ERRNO, zstrerror());
- return -1;
- }
- state->x.next += got;
+ have = (unsigned)(strm->next_out - state->x.next);
+ if (have && ((got = write(state->fd, state->x.next, have)) < 0 || (unsigned)got != have)) {
+ gz_error(state, Z_ERRNO, zstrerror());
+ return -1;
}
if (strm->avail_out == 0) {
strm->avail_out = state->size;
strm->next_out = state->out;
}
+ state->x.next = strm->next_out;
}
/* compress */