Loop on write() calls in gzwrite.c in case of non-blocking I/O.

This commit is contained in:
Mark Adler 2016-04-05 03:09:59 -07:00
parent 4423fef8dc
commit 4f1df003ed

View File

@ -82,12 +82,15 @@ local int gz_comp(state, flush)
/* write directly if requested */ /* write directly if requested */
if (state->direct) { if (state->direct) {
got = write(state->fd, strm->next_in, strm->avail_in); while (strm->avail_in) {
if (got < 0 || (unsigned)got != strm->avail_in) { got = write(state->fd, strm->next_in, strm->avail_in);
gz_error(state, Z_ERRNO, zstrerror()); if (got < 0) {
return -1; gz_error(state, Z_ERRNO, zstrerror());
return -1;
}
strm->avail_in -= got;
strm->next_in += got;
} }
strm->avail_in = 0;
return 0; return 0;
} }
@ -98,17 +101,19 @@ local int gz_comp(state, flush)
doing Z_FINISH then don't write until we get to Z_STREAM_END */ doing Z_FINISH then don't write until we get to Z_STREAM_END */
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
(flush != Z_FINISH || ret == Z_STREAM_END))) { (flush != Z_FINISH || ret == Z_STREAM_END))) {
have = (unsigned)(strm->next_out - state->x.next); while (strm->next_out > state->x.next) {
if (have && ((got = write(state->fd, state->x.next, have)) < 0 || got = write(state->fd, state->x.next,
(unsigned)got != have)) { strm->next_out - state->x.next);
gz_error(state, Z_ERRNO, zstrerror()); if (got < 0) {
return -1; gz_error(state, Z_ERRNO, zstrerror());
return -1;
}
state->x.next += got;
} }
if (strm->avail_out == 0) { if (strm->avail_out == 0) {
strm->avail_out = state->size; strm->avail_out = state->size;
strm->next_out = state->out; strm->next_out = state->out;
} }
state->x.next = strm->next_out;
} }
/* compress */ /* compress */