diff options
| -rw-r--r-- | gzwrite.c | 27 |
1 files changed, 16 insertions, 11 deletions
| @@ -82,12 +82,15 @@ local int gz_comp(state, flush) | |||
| 82 | 82 | ||
| 83 | /* write directly if requested */ | 83 | /* write directly if requested */ |
| 84 | if (state->direct) { | 84 | if (state->direct) { |
| 85 | got = write(state->fd, strm->next_in, strm->avail_in); | 85 | while (strm->avail_in) { |
| 86 | if (got < 0 || (unsigned)got != strm->avail_in) { | 86 | got = write(state->fd, strm->next_in, strm->avail_in); |
| 87 | gz_error(state, Z_ERRNO, zstrerror()); | 87 | if (got < 0) { |
| 88 | return -1; | 88 | gz_error(state, Z_ERRNO, zstrerror()); |
| 89 | return -1; | ||
| 90 | } | ||
| 91 | strm->avail_in -= got; | ||
| 92 | strm->next_in += got; | ||
| 89 | } | 93 | } |
| 90 | strm->avail_in = 0; | ||
| 91 | return 0; | 94 | return 0; |
| 92 | } | 95 | } |
| 93 | 96 | ||
| @@ -98,17 +101,19 @@ local int gz_comp(state, flush) | |||
| 98 | doing Z_FINISH then don't write until we get to Z_STREAM_END */ | 101 | doing Z_FINISH then don't write until we get to Z_STREAM_END */ |
| 99 | if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && | 102 | if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && |
| 100 | (flush != Z_FINISH || ret == Z_STREAM_END))) { | 103 | (flush != Z_FINISH || ret == Z_STREAM_END))) { |
| 101 | have = (unsigned)(strm->next_out - state->x.next); | 104 | while (strm->next_out > state->x.next) { |
| 102 | if (have && ((got = write(state->fd, state->x.next, have)) < 0 || | 105 | got = write(state->fd, state->x.next, |
| 103 | (unsigned)got != have)) { | 106 | strm->next_out - state->x.next); |
| 104 | gz_error(state, Z_ERRNO, zstrerror()); | 107 | if (got < 0) { |
| 105 | return -1; | 108 | gz_error(state, Z_ERRNO, zstrerror()); |
| 109 | return -1; | ||
| 110 | } | ||
| 111 | state->x.next += got; | ||
| 106 | } | 112 | } |
| 107 | if (strm->avail_out == 0) { | 113 | if (strm->avail_out == 0) { |
| 108 | strm->avail_out = state->size; | 114 | strm->avail_out = state->size; |
| 109 | strm->next_out = state->out; | 115 | strm->next_out = state->out; |
| 110 | } | 116 | } |
| 111 | state->x.next = strm->next_out; | ||
| 112 | } | 117 | } |
| 113 | 118 | ||
| 114 | /* compress */ | 119 | /* compress */ |
