Add casts and consts to ease user conversion to C++.
authorMark Adler <madler@alumni.caltech.edu>
Sun, 24 Mar 2013 22:18:02 +0000 (15:18 -0700)
committerMark Adler <madler@alumni.caltech.edu>
Sun, 24 Mar 2013 23:09:08 +0000 (16:09 -0700)
You would still need to run zlib2ansi on all of the *.c files.

gzlib.c
gzread.c
gzwrite.c
zconf.h
zconf.h.cmakein
zconf.h.in

diff --git a/gzlib.c b/gzlib.c
index e4ca5768ed6a5e8968ce963ebb50be9285c130de..0500d6ca2f3bc658c62f880397a53bfcca11d1fd 100644 (file)
--- a/gzlib.c
+++ b/gzlib.c
@@ -108,7 +108,7 @@ local gzFile gz_open(path, fd, mode)
         return NULL;
 
     /* allocate gzFile structure to return */
-    state = malloc(sizeof(gz_state));
+    state = (gz_statep)malloc(sizeof(gz_state));
     if (state == NULL)
         return NULL;
     state->size = 0;            /* no buffers allocated yet */
@@ -196,8 +196,8 @@ local gzFile gz_open(path, fd, mode)
     }
     else
 #endif
-        len = strlen(path);
-    state->path = malloc(len + 1);
+        len = strlen((const char *)path);
+    state->path = (char *)malloc(len + 1);
     if (state->path == NULL) {
         free(state);
         return NULL;
@@ -242,7 +242,7 @@ local gzFile gz_open(path, fd, mode)
 #ifdef _WIN32
         fd == -2 ? _wopen(path, oflag, 0666) :
 #endif
-        open(path, oflag, 0666));
+        open((const char *)path, oflag, 0666));
     if (state->fd == -1) {
         free(state->path);
         free(state);
@@ -288,7 +288,7 @@ gzFile ZEXPORT gzdopen(fd, mode)
     char *path;         /* identifier for error messages */
     gzFile gz;
 
-    if (fd == -1 || (path = malloc(7 + 3 * sizeof(int))) == NULL)
+    if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
         return NULL;
 #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
     snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd); /* for debugging */
@@ -598,7 +598,8 @@ void ZLIB_INTERNAL gz_error(state, err, msg)
         return;
 
     /* construct error message with path */
-    if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) {
+    if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) ==
+            NULL) {
         state->err = Z_MEM_ERROR;
         return;
     }
index 52985c9e7bb44513f5393a4feb8c4482f5e6a13c..3b497cf737f2611f8d9d9149584c54380271dfc2 100644 (file)
--- a/gzread.c
+++ b/gzread.c
@@ -91,8 +91,8 @@ local int gz_look(state)
     /* allocate read buffers and inflate memory */
     if (state->size == 0) {
         /* allocate buffers */
-        state->in = malloc(state->want);
-        state->out = malloc(state->want << 1);
+        state->in = (unsigned char *)malloc(state->want);
+        state->out = (unsigned char *)malloc(state->want << 1);
         if (state->in == NULL || state->out == NULL) {
             if (state->out != NULL)
                 free(state->out);
@@ -353,14 +353,14 @@ int ZEXPORT gzread(file, buf, len)
 
         /* large len -- read directly into user buffer */
         else if (state->how == COPY) {      /* read directly */
-            if (gz_load(state, buf, len, &n) == -1)
+            if (gz_load(state, (unsigned char *)buf, len, &n) == -1)
                 return -1;
         }
 
         /* large len -- decompress directly into user buffer */
         else {  /* state->how == GZIP */
             strm->avail_out = len;
-            strm->next_out = buf;
+            strm->next_out = (unsigned char *)buf;
             if (gz_decomp(state) == -1)
                 return -1;
             n = state->x.have;
@@ -523,7 +523,7 @@ char * ZEXPORT gzgets(file, buf, len)
 
         /* look for end-of-line in current output buffer */
         n = state->x.have > left ? left : state->x.have;
-        eol = memchr(state->x.next, '\n', n);
+        eol = (unsigned char *)memchr(state->x.next, '\n', n);
         if (eol != NULL)
             n = (unsigned)(eol - state->x.next) + 1;
 
index 039225bd1da696b041335b9c594635ce7ad0b53b..e8c5efd60a9c75613aea84bd6bd0b2a09adb02b0 100644 (file)
--- a/gzwrite.c
+++ b/gzwrite.c
@@ -19,7 +19,7 @@ local int gz_init(state)
     z_streamp strm = &(state->strm);
 
     /* allocate input buffer */
-    state->in = malloc(state->want);
+    state->in = (unsigned char *)malloc(state->want);
     if (state->in == NULL) {
         gz_error(state, Z_MEM_ERROR, "out of memory");
         return -1;
@@ -28,7 +28,7 @@ local int gz_init(state)
     /* only need output buffer and deflate state if compressing */
     if (!state->direct) {
         /* allocate output buffer */
-        state->out = malloc(state->want);
+        state->out = (unsigned char *)malloc(state->want);
         if (state->out == NULL) {
             free(state->in);
             gz_error(state, Z_MEM_ERROR, "out of memory");
diff --git a/zconf.h b/zconf.h
index 371f755b67c1f49bc96996b9057cd668eb776173..aed84f2433f15a784c058cdb82db960eb5b4618b 100644 (file)
--- a/zconf.h
+++ b/zconf.h
 #  endif
 #endif
 
-#if defined(ZLIB_CONST) && !defined(z_const)
+#if ( defined(ZLIB_CONST) || defined(__cplusplus) ) && !defined(z_const)
 #  define z_const const
 #else
 #  define z_const
index ae8799efaf3f9d621265f0f04c7b5d48ae954b98..543ad468ef960e674126334db592a9da8f596a8e 100644 (file)
 #  endif
 #endif
 
-#if defined(ZLIB_CONST) && !defined(z_const)
+#if ( defined(ZLIB_CONST) || defined(__cplusplus) ) && !defined(z_const)
 #  define z_const const
 #else
 #  define z_const
index 371f755b67c1f49bc96996b9057cd668eb776173..aed84f2433f15a784c058cdb82db960eb5b4618b 100644 (file)
 #  endif
 #endif
 
-#if defined(ZLIB_CONST) && !defined(z_const)
+#if ( defined(ZLIB_CONST) || defined(__cplusplus) ) && !defined(z_const)
 #  define z_const const
 #else
 #  define z_const