summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2013-03-24 15:18:02 -0700
committerMark Adler <madler@alumni.caltech.edu>2013-03-24 16:09:08 -0700
commite9f0b78443884bfd88ead7235bcf5a6a1adae5cd (patch)
tree05561b485bbc8fe51a56634590d8eac025a247a5
parent0aac8cf7c4da2572609d177657fb5f947bf38cd2 (diff)
downloadzlib-e9f0b78443884bfd88ead7235bcf5a6a1adae5cd.tar.gz
zlib-e9f0b78443884bfd88ead7235bcf5a6a1adae5cd.tar.bz2
zlib-e9f0b78443884bfd88ead7235bcf5a6a1adae5cd.zip
Add casts and consts to ease user conversion to C++.
You would still need to run zlib2ansi on all of the *.c files.
-rw-r--r--gzlib.c13
-rw-r--r--gzread.c10
-rw-r--r--gzwrite.c4
-rw-r--r--zconf.h2
-rw-r--r--zconf.h.cmakein2
-rw-r--r--zconf.h.in2
6 files changed, 17 insertions, 16 deletions
diff --git a/gzlib.c b/gzlib.c
index e4ca576..0500d6c 100644
--- a/gzlib.c
+++ b/gzlib.c
@@ -108,7 +108,7 @@ local gzFile gz_open(path, fd, mode)
108 return NULL; 108 return NULL;
109 109
110 /* allocate gzFile structure to return */ 110 /* allocate gzFile structure to return */
111 state = malloc(sizeof(gz_state)); 111 state = (gz_statep)malloc(sizeof(gz_state));
112 if (state == NULL) 112 if (state == NULL)
113 return NULL; 113 return NULL;
114 state->size = 0; /* no buffers allocated yet */ 114 state->size = 0; /* no buffers allocated yet */
@@ -196,8 +196,8 @@ local gzFile gz_open(path, fd, mode)
196 } 196 }
197 else 197 else
198#endif 198#endif
199 len = strlen(path); 199 len = strlen((const char *)path);
200 state->path = malloc(len + 1); 200 state->path = (char *)malloc(len + 1);
201 if (state->path == NULL) { 201 if (state->path == NULL) {
202 free(state); 202 free(state);
203 return NULL; 203 return NULL;
@@ -242,7 +242,7 @@ local gzFile gz_open(path, fd, mode)
242#ifdef _WIN32 242#ifdef _WIN32
243 fd == -2 ? _wopen(path, oflag, 0666) : 243 fd == -2 ? _wopen(path, oflag, 0666) :
244#endif 244#endif
245 open(path, oflag, 0666)); 245 open((const char *)path, oflag, 0666));
246 if (state->fd == -1) { 246 if (state->fd == -1) {
247 free(state->path); 247 free(state->path);
248 free(state); 248 free(state);
@@ -288,7 +288,7 @@ gzFile ZEXPORT gzdopen(fd, mode)
288 char *path; /* identifier for error messages */ 288 char *path; /* identifier for error messages */
289 gzFile gz; 289 gzFile gz;
290 290
291 if (fd == -1 || (path = malloc(7 + 3 * sizeof(int))) == NULL) 291 if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
292 return NULL; 292 return NULL;
293#if !defined(NO_snprintf) && !defined(NO_vsnprintf) 293#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
294 snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd); /* for debugging */ 294 snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd); /* for debugging */
@@ -598,7 +598,8 @@ void ZLIB_INTERNAL gz_error(state, err, msg)
598 return; 598 return;
599 599
600 /* construct error message with path */ 600 /* construct error message with path */
601 if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { 601 if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) ==
602 NULL) {
602 state->err = Z_MEM_ERROR; 603 state->err = Z_MEM_ERROR;
603 return; 604 return;
604 } 605 }
diff --git a/gzread.c b/gzread.c
index 52985c9..3b497cf 100644
--- a/gzread.c
+++ b/gzread.c
@@ -91,8 +91,8 @@ local int gz_look(state)
91 /* allocate read buffers and inflate memory */ 91 /* allocate read buffers and inflate memory */
92 if (state->size == 0) { 92 if (state->size == 0) {
93 /* allocate buffers */ 93 /* allocate buffers */
94 state->in = malloc(state->want); 94 state->in = (unsigned char *)malloc(state->want);
95 state->out = malloc(state->want << 1); 95 state->out = (unsigned char *)malloc(state->want << 1);
96 if (state->in == NULL || state->out == NULL) { 96 if (state->in == NULL || state->out == NULL) {
97 if (state->out != NULL) 97 if (state->out != NULL)
98 free(state->out); 98 free(state->out);
@@ -353,14 +353,14 @@ int ZEXPORT gzread(file, buf, len)
353 353
354 /* large len -- read directly into user buffer */ 354 /* large len -- read directly into user buffer */
355 else if (state->how == COPY) { /* read directly */ 355 else if (state->how == COPY) { /* read directly */
356 if (gz_load(state, buf, len, &n) == -1) 356 if (gz_load(state, (unsigned char *)buf, len, &n) == -1)
357 return -1; 357 return -1;
358 } 358 }
359 359
360 /* large len -- decompress directly into user buffer */ 360 /* large len -- decompress directly into user buffer */
361 else { /* state->how == GZIP */ 361 else { /* state->how == GZIP */
362 strm->avail_out = len; 362 strm->avail_out = len;
363 strm->next_out = buf; 363 strm->next_out = (unsigned char *)buf;
364 if (gz_decomp(state) == -1) 364 if (gz_decomp(state) == -1)
365 return -1; 365 return -1;
366 n = state->x.have; 366 n = state->x.have;
@@ -523,7 +523,7 @@ char * ZEXPORT gzgets(file, buf, len)
523 523
524 /* look for end-of-line in current output buffer */ 524 /* look for end-of-line in current output buffer */
525 n = state->x.have > left ? left : state->x.have; 525 n = state->x.have > left ? left : state->x.have;
526 eol = memchr(state->x.next, '\n', n); 526 eol = (unsigned char *)memchr(state->x.next, '\n', n);
527 if (eol != NULL) 527 if (eol != NULL)
528 n = (unsigned)(eol - state->x.next) + 1; 528 n = (unsigned)(eol - state->x.next) + 1;
529 529
diff --git a/gzwrite.c b/gzwrite.c
index 039225b..e8c5efd 100644
--- a/gzwrite.c
+++ b/gzwrite.c
@@ -19,7 +19,7 @@ local int gz_init(state)
19 z_streamp strm = &(state->strm); 19 z_streamp strm = &(state->strm);
20 20
21 /* allocate input buffer */ 21 /* allocate input buffer */
22 state->in = malloc(state->want); 22 state->in = (unsigned char *)malloc(state->want);
23 if (state->in == NULL) { 23 if (state->in == NULL) {
24 gz_error(state, Z_MEM_ERROR, "out of memory"); 24 gz_error(state, Z_MEM_ERROR, "out of memory");
25 return -1; 25 return -1;
@@ -28,7 +28,7 @@ local int gz_init(state)
28 /* only need output buffer and deflate state if compressing */ 28 /* only need output buffer and deflate state if compressing */
29 if (!state->direct) { 29 if (!state->direct) {
30 /* allocate output buffer */ 30 /* allocate output buffer */
31 state->out = malloc(state->want); 31 state->out = (unsigned char *)malloc(state->want);
32 if (state->out == NULL) { 32 if (state->out == NULL) {
33 free(state->in); 33 free(state->in);
34 gz_error(state, Z_MEM_ERROR, "out of memory"); 34 gz_error(state, Z_MEM_ERROR, "out of memory");
diff --git a/zconf.h b/zconf.h
index 371f755..aed84f2 100644
--- a/zconf.h
+++ b/zconf.h
@@ -218,7 +218,7 @@
218# endif 218# endif
219#endif 219#endif
220 220
221#if defined(ZLIB_CONST) && !defined(z_const) 221#if ( defined(ZLIB_CONST) || defined(__cplusplus) ) && !defined(z_const)
222# define z_const const 222# define z_const const
223#else 223#else
224# define z_const 224# define z_const
diff --git a/zconf.h.cmakein b/zconf.h.cmakein
index ae8799e..543ad46 100644
--- a/zconf.h.cmakein
+++ b/zconf.h.cmakein
@@ -220,7 +220,7 @@
220# endif 220# endif
221#endif 221#endif
222 222
223#if defined(ZLIB_CONST) && !defined(z_const) 223#if ( defined(ZLIB_CONST) || defined(__cplusplus) ) && !defined(z_const)
224# define z_const const 224# define z_const const
225#else 225#else
226# define z_const 226# define z_const
diff --git a/zconf.h.in b/zconf.h.in
index 371f755..aed84f2 100644
--- a/zconf.h.in
+++ b/zconf.h.in
@@ -218,7 +218,7 @@
218# endif 218# endif
219#endif 219#endif
220 220
221#if defined(ZLIB_CONST) && !defined(z_const) 221#if ( defined(ZLIB_CONST) || defined(__cplusplus) ) && !defined(z_const)
222# define z_const const 222# define z_const const
223#else 223#else
224# define z_const 224# define z_const