diff options
| author | Mark Adler <madler@alumni.caltech.edu> | 2016-12-03 10:27:14 -0800 |
|---|---|---|
| committer | Mark Adler <madler@alumni.caltech.edu> | 2016-12-04 07:48:48 -0800 |
| commit | ca50ebd4dfd08dfd7e8c8bb087278e158cd67720 (patch) | |
| tree | 9262ad9bb1dde6992b41093614d75d63eea2bf31 | |
| parent | c5ee34c28a9144b1b5a5021d05ed29940c53010c (diff) | |
| download | zlib-ca50ebd4dfd08dfd7e8c8bb087278e158cd67720.tar.gz zlib-ca50ebd4dfd08dfd7e8c8bb087278e158cd67720.tar.bz2 zlib-ca50ebd4dfd08dfd7e8c8bb087278e158cd67720.zip | |
Create z_size_t and z_ssize_t types.
Normally these are set to size_t and ssize_t. But if they do not
exist, then they are set to the smallest integer type that can
contain a pointer. size_t is unsigned and ssize_t is signed.
| -rwxr-xr-x | configure | 106 | ||||
| -rw-r--r-- | gzlib.c | 4 | ||||
| -rw-r--r-- | gzread.c | 2 | ||||
| -rw-r--r-- | gzwrite.c | 2 | ||||
| -rw-r--r-- | test/minigzip.c | 2 | ||||
| -rw-r--r-- | zconf.h | 15 | ||||
| -rw-r--r-- | zconf.h.cmakein | 15 | ||||
| -rw-r--r-- | zconf.h.in | 15 |
8 files changed, 144 insertions, 17 deletions
| @@ -181,9 +181,12 @@ show $cc -c $test.c | |||
| 181 | if test "$gcc" -eq 1 && ($cc -c $test.c) >> configure.log 2>&1; then | 181 | if test "$gcc" -eq 1 && ($cc -c $test.c) >> configure.log 2>&1; then |
| 182 | echo ... using gcc >> configure.log | 182 | echo ... using gcc >> configure.log |
| 183 | CC="$cc" | 183 | CC="$cc" |
| 184 | CFLAGS="${CFLAGS--O3} ${ARCHS}" | 184 | CFLAGS="${CFLAGS--O3}" |
| 185 | SFLAGS="${CFLAGS--O3} -fPIC" | 185 | SFLAGS="${CFLAGS--O3} -fPIC" |
| 186 | LDFLAGS="${LDFLAGS} ${ARCHS}" | 186 | if test "$ARCHS"; then |
| 187 | CFLAGS="${CFLAGS} ${ARCHS}" | ||
| 188 | LDFLAGS="${LDFLAGS} ${ARCHS}" | ||
| 189 | fi | ||
| 187 | if test $build64 -eq 1; then | 190 | if test $build64 -eq 1; then |
| 188 | CFLAGS="${CFLAGS} -m64" | 191 | CFLAGS="${CFLAGS} -m64" |
| 189 | SFLAGS="${SFLAGS} -m64" | 192 | SFLAGS="${SFLAGS} -m64" |
| @@ -360,16 +363,16 @@ if ($CC -c $CFLAGS $test.c) 2>/dev/null; then | |||
| 360 | } | 363 | } |
| 361 | echo - using any output from compiler to indicate an error >> configure.log | 364 | echo - using any output from compiler to indicate an error >> configure.log |
| 362 | else | 365 | else |
| 363 | try() | 366 | try() |
| 364 | { | 367 | { |
| 365 | show $* | 368 | show $* |
| 366 | ( $* ) >> configure.log 2>&1 | 369 | ( $* ) >> configure.log 2>&1 |
| 367 | ret=$? | 370 | ret=$? |
| 368 | if test $ret -ne 0; then | 371 | if test $ret -ne 0; then |
| 369 | echo "(exit code "$ret")" >> configure.log | 372 | echo "(exit code "$ret")" >> configure.log |
| 370 | fi | 373 | fi |
| 371 | return $ret | 374 | return $ret |
| 372 | } | 375 | } |
| 373 | fi | 376 | fi |
| 374 | 377 | ||
| 375 | tryboth() | 378 | tryboth() |
| @@ -445,6 +448,85 @@ esac | |||
| 445 | 448 | ||
| 446 | echo >> configure.log | 449 | echo >> configure.log |
| 447 | 450 | ||
| 451 | # check for size_t | ||
| 452 | cat > $test.c <<EOF | ||
| 453 | #include <stdio.h> | ||
| 454 | #include <stdlib.h> | ||
| 455 | size_t dummy = 0; | ||
| 456 | EOF | ||
| 457 | if try $CC -c $CFLAGS $test.c; then | ||
| 458 | echo "Checking for size_t... Yes." | tee -a configure.log | ||
| 459 | need_sizet=0 | ||
| 460 | else | ||
| 461 | echo "Checking for size_t... No." | tee -a configure.log | ||
| 462 | need_sizet=1 | ||
| 463 | fi | ||
| 464 | |||
| 465 | echo >> configure.log | ||
| 466 | |||
| 467 | # check for ssize_t | ||
| 468 | cat > $test.c <<EOF | ||
| 469 | #include <sys/types.h> | ||
| 470 | ssize_t dummy = 0; | ||
| 471 | EOF | ||
| 472 | if try $CC -c $CFLAGS $test.c; then | ||
| 473 | echo "Checking for ssize_t... Yes." | tee -a configure.log | ||
| 474 | need_ssizet=0 | ||
| 475 | else | ||
| 476 | echo "Checking for ssize_t... No." | tee -a configure.log | ||
| 477 | need_ssizet=1 | ||
| 478 | fi | ||
| 479 | |||
| 480 | echo >> configure.log | ||
| 481 | |||
| 482 | # find the size_t integer type, if needed | ||
| 483 | if test $need_sizet -eq 1 -o $need_ssizet -eq 1; then | ||
| 484 | cat > $test.c <<EOF | ||
| 485 | long long dummy = 0; | ||
| 486 | EOF | ||
| 487 | if try $CC -c $CFLAGS $test.c; then | ||
| 488 | echo "Checking for long long... Yes." | tee -a configure.log | ||
| 489 | cat > $test.c <<EOF | ||
| 490 | #include <stdio.h> | ||
| 491 | int main(void) { | ||
| 492 | if (sizeof(void *) <= sizeof(int)) puts("int"); | ||
| 493 | else if (sizeof(void *) <= sizeof(long)) puts("long"); | ||
| 494 | else puts("long long"); | ||
| 495 | return 0; | ||
| 496 | } | ||
| 497 | EOF | ||
| 498 | else | ||
| 499 | echo "Checking for long long... No." | tee -a configure.log | ||
| 500 | cat > $test.c <<EOF | ||
| 501 | #include <stdio.h> | ||
| 502 | int main(void) { | ||
| 503 | if (sizeof(void *) <= sizeof(int)) puts("int"); | ||
| 504 | else puts("long"); | ||
| 505 | return 0; | ||
| 506 | } | ||
| 507 | EOF | ||
| 508 | fi | ||
| 509 | if try $CC $CFLAGS -o $test $test.c; then | ||
| 510 | sizet=`./$test` | ||
| 511 | echo "Checking for a pointer-size integer type..." $sizet"." | tee -a configure.log | ||
| 512 | else | ||
| 513 | echo "Failed to find a pointer-size integer type." | tee -a configure.log | ||
| 514 | leave 1 | ||
| 515 | fi | ||
| 516 | fi | ||
| 517 | |||
| 518 | if test $need_sizet -eq 1; then | ||
| 519 | CFLAGS="${CFLAGS} -DNO_SIZE_T=${sizet}" | ||
| 520 | SFLAGS="${SFLAGS} -DNO_SIZE_T=${sizet}" | ||
| 521 | fi | ||
| 522 | |||
| 523 | if test $need_ssizet -eq 1; then | ||
| 524 | CFLAGS="${CFLAGS} -DNO_SSIZE_T=${sizet}" | ||
| 525 | SFLAGS="${SFLAGS} -DNO_SSIZE_T=${sizet}" | ||
| 526 | fi | ||
| 527 | |||
| 528 | echo >> configure.log | ||
| 529 | |||
| 448 | # check for large file support, and if none, check for fseeko() | 530 | # check for large file support, and if none, check for fseeko() |
| 449 | cat > $test.c <<EOF | 531 | cat > $test.c <<EOF |
| 450 | #include <sys/types.h> | 532 | #include <sys/types.h> |
| @@ -94,7 +94,7 @@ local gzFile gz_open(path, fd, mode) | |||
| 94 | const char *mode; | 94 | const char *mode; |
| 95 | { | 95 | { |
| 96 | gz_statep state; | 96 | gz_statep state; |
| 97 | size_t len; | 97 | z_size_t len; |
| 98 | int oflag; | 98 | int oflag; |
| 99 | #ifdef O_CLOEXEC | 99 | #ifdef O_CLOEXEC |
| 100 | int cloexec = 0; | 100 | int cloexec = 0; |
| @@ -191,7 +191,7 @@ local gzFile gz_open(path, fd, mode) | |||
| 191 | #ifdef WIDECHAR | 191 | #ifdef WIDECHAR |
| 192 | if (fd == -2) { | 192 | if (fd == -2) { |
| 193 | len = wcstombs(NULL, path, 0); | 193 | len = wcstombs(NULL, path, 0); |
| 194 | if (len == (size_t)-1) | 194 | if (len == (z_size_t)-1) |
| 195 | len = 0; | 195 | len = 0; |
| 196 | } | 196 | } |
| 197 | else | 197 | else |
| @@ -23,7 +23,7 @@ local int gz_load(state, buf, len, have) | |||
| 23 | unsigned len; | 23 | unsigned len; |
| 24 | unsigned *have; | 24 | unsigned *have; |
| 25 | { | 25 | { |
| 26 | ssize_t ret; | 26 | z_ssize_t ret; |
| 27 | 27 | ||
| 28 | *have = 0; | 28 | *have = 0; |
| 29 | do { | 29 | do { |
| @@ -74,7 +74,7 @@ local int gz_comp(state, flush) | |||
| 74 | int flush; | 74 | int flush; |
| 75 | { | 75 | { |
| 76 | int ret; | 76 | int ret; |
| 77 | ssize_t got; | 77 | z_ssize_t got; |
| 78 | unsigned have; | 78 | unsigned have; |
| 79 | z_streamp strm = &(state->strm); | 79 | z_streamp strm = &(state->strm); |
| 80 | 80 | ||
diff --git a/test/minigzip.c b/test/minigzip.c index f4ffbe2..6c64cc7 100644 --- a/test/minigzip.c +++ b/test/minigzip.c | |||
| @@ -500,7 +500,7 @@ void file_uncompress(file) | |||
| 500 | char *infile, *outfile; | 500 | char *infile, *outfile; |
| 501 | FILE *out; | 501 | FILE *out; |
| 502 | gzFile in; | 502 | gzFile in; |
| 503 | size_t len = strlen(file); | 503 | z_size_t len = strlen(file); |
| 504 | 504 | ||
| 505 | if (len + strlen(GZ_SUFFIX) >= sizeof(buf)) { | 505 | if (len + strlen(GZ_SUFFIX) >= sizeof(buf)) { |
| 506 | fprintf(stderr, "%s: filename too long\n", prog); | 506 | fprintf(stderr, "%s: filename too long\n", prog); |
| @@ -224,6 +224,21 @@ | |||
| 224 | # define z_const | 224 | # define z_const |
| 225 | #endif | 225 | #endif |
| 226 | 226 | ||
| 227 | #ifndef Z_SOLO | ||
| 228 | # ifdef NO_SIZE_T | ||
| 229 | typedef unsigned NO_SIZE_T z_size_t; | ||
| 230 | # else | ||
| 231 | # include <stddef.h> | ||
| 232 | typedef size_t z_size_t; | ||
| 233 | # endif | ||
| 234 | # ifdef NO_SSIZE_T | ||
| 235 | typedef NO_SSIZE_T z_ssize_t; | ||
| 236 | # else | ||
| 237 | # include <sys/types.h> | ||
| 238 | typedef ssize_t z_ssize_t; | ||
| 239 | # endif | ||
| 240 | #endif | ||
| 241 | |||
| 227 | /* Maximum value for memLevel in deflateInit2 */ | 242 | /* Maximum value for memLevel in deflateInit2 */ |
| 228 | #ifndef MAX_MEM_LEVEL | 243 | #ifndef MAX_MEM_LEVEL |
| 229 | # ifdef MAXSEG_64K | 244 | # ifdef MAXSEG_64K |
diff --git a/zconf.h.cmakein b/zconf.h.cmakein index 70942e4..662fc3d 100644 --- a/zconf.h.cmakein +++ b/zconf.h.cmakein | |||
| @@ -226,6 +226,21 @@ | |||
| 226 | # define z_const | 226 | # define z_const |
| 227 | #endif | 227 | #endif |
| 228 | 228 | ||
| 229 | #ifndef Z_SOLO | ||
| 230 | # ifdef NO_SIZE_T | ||
| 231 | typedef unsigned NO_SIZE_T z_size_t; | ||
| 232 | # else | ||
| 233 | # include <stddef.h> | ||
| 234 | typedef size_t z_size_t; | ||
| 235 | # endif | ||
| 236 | # ifdef NO_SSIZE_T | ||
| 237 | typedef NO_SSIZE_T z_ssize_t; | ||
| 238 | # else | ||
| 239 | # include <sys/types.h> | ||
| 240 | typedef ssize_t z_ssize_t; | ||
| 241 | # endif | ||
| 242 | #endif | ||
| 243 | |||
| 229 | /* Maximum value for memLevel in deflateInit2 */ | 244 | /* Maximum value for memLevel in deflateInit2 */ |
| 230 | #ifndef MAX_MEM_LEVEL | 245 | #ifndef MAX_MEM_LEVEL |
| 231 | # ifdef MAXSEG_64K | 246 | # ifdef MAXSEG_64K |
| @@ -224,6 +224,21 @@ | |||
| 224 | # define z_const | 224 | # define z_const |
| 225 | #endif | 225 | #endif |
| 226 | 226 | ||
| 227 | #ifndef Z_SOLO | ||
| 228 | # ifdef NO_SIZE_T | ||
| 229 | typedef unsigned NO_SIZE_T z_size_t; | ||
| 230 | # else | ||
| 231 | # include <stddef.h> | ||
| 232 | typedef size_t z_size_t; | ||
| 233 | # endif | ||
| 234 | # ifdef NO_SSIZE_T | ||
| 235 | typedef NO_SSIZE_T z_ssize_t; | ||
| 236 | # else | ||
| 237 | # include <sys/types.h> | ||
| 238 | typedef ssize_t z_ssize_t; | ||
| 239 | # endif | ||
| 240 | #endif | ||
| 241 | |||
| 227 | /* Maximum value for memLevel in deflateInit2 */ | 242 | /* Maximum value for memLevel in deflateInit2 */ |
| 228 | #ifndef MAX_MEM_LEVEL | 243 | #ifndef MAX_MEM_LEVEL |
| 229 | # ifdef MAXSEG_64K | 244 | # ifdef MAXSEG_64K |
