diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2013-03-24 15:18:02 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2013-03-24 16:09:08 -0700 |
commit | e9f0b78443884bfd88ead7235bcf5a6a1adae5cd (patch) | |
tree | 05561b485bbc8fe51a56634590d8eac025a247a5 | |
parent | 0aac8cf7c4da2572609d177657fb5f947bf38cd2 (diff) | |
download | zlib-e9f0b78443884bfd88ead7235bcf5a6a1adae5cd.tar.gz |
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.c | 13 | ||||
-rw-r--r-- | gzread.c | 10 | ||||
-rw-r--r-- | gzwrite.c | 4 | ||||
-rw-r--r-- | zconf.h | 2 | ||||
-rw-r--r-- | zconf.h.cmakein | 2 | ||||
-rw-r--r-- | zconf.h.in | 2 |
6 files changed, 17 insertions, 16 deletions
@@ -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; } @@ -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; @@ -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"); @@ -218,7 +218,7 @@ # 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 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 @@ # 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 @@ -218,7 +218,7 @@ # 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 |