diff options
Diffstat (limited to 'gzwrite.c')
-rw-r--r-- | gzwrite.c | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -74,9 +74,8 @@ local int gz_comp(state, flush) | |||
74 | gz_statep state; | 74 | gz_statep state; |
75 | int flush; | 75 | int flush; |
76 | { | 76 | { |
77 | int ret; | 77 | int ret, writ; |
78 | z_ssize_t got; | 78 | unsigned have, put, max = ((unsigned)-1 >> 2) + 1; |
79 | unsigned have; | ||
80 | z_streamp strm = &(state->strm); | 79 | z_streamp strm = &(state->strm); |
81 | 80 | ||
82 | /* allocate memory if this is the first time through */ | 81 | /* allocate memory if this is the first time through */ |
@@ -86,13 +85,14 @@ local int gz_comp(state, flush) | |||
86 | /* write directly if requested */ | 85 | /* write directly if requested */ |
87 | if (state->direct) { | 86 | if (state->direct) { |
88 | while (strm->avail_in) { | 87 | while (strm->avail_in) { |
89 | got = write(state->fd, strm->next_in, strm->avail_in); | 88 | put = strm->avail_in > max ? max : strm->avail_in; |
90 | if (got < 0) { | 89 | writ = write(state->fd, strm->next_in, put); |
90 | if (writ < 0) { | ||
91 | gz_error(state, Z_ERRNO, zstrerror()); | 91 | gz_error(state, Z_ERRNO, zstrerror()); |
92 | return -1; | 92 | return -1; |
93 | } | 93 | } |
94 | strm->avail_in -= (unsigned)got; | 94 | strm->avail_in -= (unsigned)writ; |
95 | strm->next_in += got; | 95 | strm->next_in += writ; |
96 | } | 96 | } |
97 | return 0; | 97 | return 0; |
98 | } | 98 | } |
@@ -105,13 +105,14 @@ local int gz_comp(state, flush) | |||
105 | if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && | 105 | if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && |
106 | (flush != Z_FINISH || ret == Z_STREAM_END))) { | 106 | (flush != Z_FINISH || ret == Z_STREAM_END))) { |
107 | while (strm->next_out > state->x.next) { | 107 | while (strm->next_out > state->x.next) { |
108 | got = write(state->fd, state->x.next, | 108 | put = strm->next_out - state->x.next > (int)max ? max : |
109 | (unsigned long)(strm->next_out - state->x.next)); | 109 | (unsigned)(strm->next_out - state->x.next); |
110 | if (got < 0) { | 110 | writ = write(state->fd, state->x.next, put); |
111 | if (writ < 0) { | ||
111 | gz_error(state, Z_ERRNO, zstrerror()); | 112 | gz_error(state, Z_ERRNO, zstrerror()); |
112 | return -1; | 113 | return -1; |
113 | } | 114 | } |
114 | state->x.next += got; | 115 | state->x.next += writ; |
115 | } | 116 | } |
116 | if (strm->avail_out == 0) { | 117 | if (strm->avail_out == 0) { |
117 | strm->avail_out = state->size; | 118 | strm->avail_out = state->size; |