aboutsummaryrefslogtreecommitdiff
path: root/gzwrite.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2012-08-12 18:08:52 -0700
committerMark Adler <madler@alumni.caltech.edu>2012-08-13 00:02:40 -0700
commit62d6112a7981ad7c34f3b43cffdf00d4662a4f25 (patch)
treeaed93070f7e1be31868dce1d62a1de6ffc1360f9 /gzwrite.c
parentfb4e0599a5ddaef9eee726f786b9edef4943432b (diff)
downloadzlib-62d6112a7981ad7c34f3b43cffdf00d4662a4f25.tar.gz
zlib-62d6112a7981ad7c34f3b43cffdf00d4662a4f25.tar.bz2
zlib-62d6112a7981ad7c34f3b43cffdf00d4662a4f25.zip
Clean up the usage of z_const and respect const usage within zlib.
This patch allows zlib to compile cleanly with the -Wcast-qual gcc warning enabled, but only if ZLIB_CONST is defined, which adds const to next_in and msg in z_stream and in the in_func prototype. A --const option is added to ./configure which adds -DZLIB_CONST to the compile flags, and adds -Wcast-qual to the compile flags when ZLIBGCCWARN is set in the environment.
Diffstat (limited to 'gzwrite.c')
-rw-r--r--gzwrite.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/gzwrite.c b/gzwrite.c
index 27cb342..bf57913 100644
--- a/gzwrite.c
+++ b/gzwrite.c
@@ -168,7 +168,6 @@ int ZEXPORT gzwrite(file, buf, len)
168 unsigned len; 168 unsigned len;
169{ 169{
170 unsigned put = len; 170 unsigned put = len;
171 unsigned n;
172 gz_statep state; 171 gz_statep state;
173 z_streamp strm; 172 z_streamp strm;
174 173
@@ -208,16 +207,19 @@ int ZEXPORT gzwrite(file, buf, len)
208 if (len < state->size) { 207 if (len < state->size) {
209 /* copy to input buffer, compress when full */ 208 /* copy to input buffer, compress when full */
210 do { 209 do {
210 unsigned have, copy;
211
211 if (strm->avail_in == 0) 212 if (strm->avail_in == 0)
212 strm->next_in = state->in; 213 strm->next_in = state->in;
213 n = state->size - strm->avail_in; 214 have = strm->next_in + strm->avail_in - state->in;
214 if (n > len) 215 copy = state->size - have;
215 n = len; 216 if (copy > len)
216 memcpy(strm->next_in + strm->avail_in, buf, n); 217 copy = len;
217 strm->avail_in += n; 218 memcpy(state->in + have, buf, copy);
218 state->x.pos += n; 219 strm->avail_in += copy;
219 buf = (char *)buf + n; 220 state->x.pos += copy;
220 len -= n; 221 buf = (const char *)buf + copy;
222 len -= copy;
221 if (len && gz_comp(state, Z_NO_FLUSH) == -1) 223 if (len && gz_comp(state, Z_NO_FLUSH) == -1)
222 return 0; 224 return 0;
223 } while (len); 225 } while (len);
@@ -229,7 +231,7 @@ int ZEXPORT gzwrite(file, buf, len)
229 231
230 /* directly compress user buffer to file */ 232 /* directly compress user buffer to file */
231 strm->avail_in = len; 233 strm->avail_in = len;
232 strm->next_in = (voidp)buf; 234 strm->next_in = (z_const Bytef *)buf;
233 state->x.pos += len; 235 state->x.pos += len;
234 if (gz_comp(state, Z_NO_FLUSH) == -1) 236 if (gz_comp(state, Z_NO_FLUSH) == -1)
235 return 0; 237 return 0;
@@ -244,6 +246,7 @@ int ZEXPORT gzputc(file, c)
244 gzFile file; 246 gzFile file;
245 int c; 247 int c;
246{ 248{
249 unsigned have;
247 unsigned char buf[1]; 250 unsigned char buf[1];
248 gz_statep state; 251 gz_statep state;
249 z_streamp strm; 252 z_streamp strm;
@@ -267,10 +270,12 @@ int ZEXPORT gzputc(file, c)
267 270
268 /* try writing to input buffer for speed (state->size == 0 if buffer not 271 /* try writing to input buffer for speed (state->size == 0 if buffer not
269 initialized) */ 272 initialized) */
270 if (strm->avail_in < state->size) { 273 if (strm->avail_in == 0)
271 if (strm->avail_in == 0) 274 strm->next_in = state->in;
272 strm->next_in = state->in; 275 have = strm->next_in + strm->avail_in - state->in;
273 strm->next_in[strm->avail_in++] = c; 276 if (have < state->size) {
277 state->in[have] = c;
278 strm->avail_in++;
274 state->x.pos++; 279 state->x.pos++;
275 return c & 0xff; 280 return c & 0xff;
276 } 281 }