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.
This commit is contained in:
Mark Adler 2016-12-03 10:27:14 -08:00
parent c5ee34c28a
commit ca50ebd4df
8 changed files with 144 additions and 17 deletions

106
configure vendored
View File

@ -181,9 +181,12 @@ show $cc -c $test.c
if test "$gcc" -eq 1 && ($cc -c $test.c) >> configure.log 2>&1; then if test "$gcc" -eq 1 && ($cc -c $test.c) >> configure.log 2>&1; then
echo ... using gcc >> configure.log echo ... using gcc >> configure.log
CC="$cc" CC="$cc"
CFLAGS="${CFLAGS--O3} ${ARCHS}" CFLAGS="${CFLAGS--O3}"
SFLAGS="${CFLAGS--O3} -fPIC" SFLAGS="${CFLAGS--O3} -fPIC"
LDFLAGS="${LDFLAGS} ${ARCHS}" if test "$ARCHS"; then
CFLAGS="${CFLAGS} ${ARCHS}"
LDFLAGS="${LDFLAGS} ${ARCHS}"
fi
if test $build64 -eq 1; then if test $build64 -eq 1; then
CFLAGS="${CFLAGS} -m64" CFLAGS="${CFLAGS} -m64"
SFLAGS="${SFLAGS} -m64" SFLAGS="${SFLAGS} -m64"
@ -360,16 +363,16 @@ if ($CC -c $CFLAGS $test.c) 2>/dev/null; then
} }
echo - using any output from compiler to indicate an error >> configure.log echo - using any output from compiler to indicate an error >> configure.log
else else
try() try()
{ {
show $* show $*
( $* ) >> configure.log 2>&1 ( $* ) >> configure.log 2>&1
ret=$? ret=$?
if test $ret -ne 0; then if test $ret -ne 0; then
echo "(exit code "$ret")" >> configure.log echo "(exit code "$ret")" >> configure.log
fi fi
return $ret return $ret
} }
fi fi
tryboth() tryboth()
@ -445,6 +448,85 @@ esac
echo >> configure.log echo >> configure.log
# check for size_t
cat > $test.c <<EOF
#include <stdio.h>
#include <stdlib.h>
size_t dummy = 0;
EOF
if try $CC -c $CFLAGS $test.c; then
echo "Checking for size_t... Yes." | tee -a configure.log
need_sizet=0
else
echo "Checking for size_t... No." | tee -a configure.log
need_sizet=1
fi
echo >> configure.log
# check for ssize_t
cat > $test.c <<EOF
#include <sys/types.h>
ssize_t dummy = 0;
EOF
if try $CC -c $CFLAGS $test.c; then
echo "Checking for ssize_t... Yes." | tee -a configure.log
need_ssizet=0
else
echo "Checking for ssize_t... No." | tee -a configure.log
need_ssizet=1
fi
echo >> configure.log
# find the size_t integer type, if needed
if test $need_sizet -eq 1 -o $need_ssizet -eq 1; then
cat > $test.c <<EOF
long long dummy = 0;
EOF
if try $CC -c $CFLAGS $test.c; then
echo "Checking for long long... Yes." | tee -a configure.log
cat > $test.c <<EOF
#include <stdio.h>
int main(void) {
if (sizeof(void *) <= sizeof(int)) puts("int");
else if (sizeof(void *) <= sizeof(long)) puts("long");
else puts("long long");
return 0;
}
EOF
else
echo "Checking for long long... No." | tee -a configure.log
cat > $test.c <<EOF
#include <stdio.h>
int main(void) {
if (sizeof(void *) <= sizeof(int)) puts("int");
else puts("long");
return 0;
}
EOF
fi
if try $CC $CFLAGS -o $test $test.c; then
sizet=`./$test`
echo "Checking for a pointer-size integer type..." $sizet"." | tee -a configure.log
else
echo "Failed to find a pointer-size integer type." | tee -a configure.log
leave 1
fi
fi
if test $need_sizet -eq 1; then
CFLAGS="${CFLAGS} -DNO_SIZE_T=${sizet}"
SFLAGS="${SFLAGS} -DNO_SIZE_T=${sizet}"
fi
if test $need_ssizet -eq 1; then
CFLAGS="${CFLAGS} -DNO_SSIZE_T=${sizet}"
SFLAGS="${SFLAGS} -DNO_SSIZE_T=${sizet}"
fi
echo >> configure.log
# check for large file support, and if none, check for fseeko() # check for large file support, and if none, check for fseeko()
cat > $test.c <<EOF cat > $test.c <<EOF
#include <sys/types.h> #include <sys/types.h>

View File

@ -94,7 +94,7 @@ local gzFile gz_open(path, fd, mode)
const char *mode; const char *mode;
{ {
gz_statep state; gz_statep state;
size_t len; z_size_t len;
int oflag; int oflag;
#ifdef O_CLOEXEC #ifdef O_CLOEXEC
int cloexec = 0; int cloexec = 0;
@ -191,7 +191,7 @@ local gzFile gz_open(path, fd, mode)
#ifdef WIDECHAR #ifdef WIDECHAR
if (fd == -2) { if (fd == -2) {
len = wcstombs(NULL, path, 0); len = wcstombs(NULL, path, 0);
if (len == (size_t)-1) if (len == (z_size_t)-1)
len = 0; len = 0;
} }
else else

View File

@ -23,7 +23,7 @@ local int gz_load(state, buf, len, have)
unsigned len; unsigned len;
unsigned *have; unsigned *have;
{ {
ssize_t ret; z_ssize_t ret;
*have = 0; *have = 0;
do { do {

View File

@ -74,7 +74,7 @@ local int gz_comp(state, flush)
int flush; int flush;
{ {
int ret; int ret;
ssize_t got; z_ssize_t got;
unsigned have; unsigned have;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);

View File

@ -500,7 +500,7 @@ void file_uncompress(file)
char *infile, *outfile; char *infile, *outfile;
FILE *out; FILE *out;
gzFile in; gzFile in;
size_t len = strlen(file); z_size_t len = strlen(file);
if (len + strlen(GZ_SUFFIX) >= sizeof(buf)) { if (len + strlen(GZ_SUFFIX) >= sizeof(buf)) {
fprintf(stderr, "%s: filename too long\n", prog); fprintf(stderr, "%s: filename too long\n", prog);

15
zconf.h
View File

@ -224,6 +224,21 @@
# define z_const # define z_const
#endif #endif
#ifndef Z_SOLO
# ifdef NO_SIZE_T
typedef unsigned NO_SIZE_T z_size_t;
# else
# include <stddef.h>
typedef size_t z_size_t;
# endif
# ifdef NO_SSIZE_T
typedef NO_SSIZE_T z_ssize_t;
# else
# include <sys/types.h>
typedef ssize_t z_ssize_t;
# endif
#endif
/* Maximum value for memLevel in deflateInit2 */ /* Maximum value for memLevel in deflateInit2 */
#ifndef MAX_MEM_LEVEL #ifndef MAX_MEM_LEVEL
# ifdef MAXSEG_64K # ifdef MAXSEG_64K

View File

@ -226,6 +226,21 @@
# define z_const # define z_const
#endif #endif
#ifndef Z_SOLO
# ifdef NO_SIZE_T
typedef unsigned NO_SIZE_T z_size_t;
# else
# include <stddef.h>
typedef size_t z_size_t;
# endif
# ifdef NO_SSIZE_T
typedef NO_SSIZE_T z_ssize_t;
# else
# include <sys/types.h>
typedef ssize_t z_ssize_t;
# endif
#endif
/* Maximum value for memLevel in deflateInit2 */ /* Maximum value for memLevel in deflateInit2 */
#ifndef MAX_MEM_LEVEL #ifndef MAX_MEM_LEVEL
# ifdef MAXSEG_64K # ifdef MAXSEG_64K

View File

@ -224,6 +224,21 @@
# define z_const # define z_const
#endif #endif
#ifndef Z_SOLO
# ifdef NO_SIZE_T
typedef unsigned NO_SIZE_T z_size_t;
# else
# include <stddef.h>
typedef size_t z_size_t;
# endif
# ifdef NO_SSIZE_T
typedef NO_SSIZE_T z_ssize_t;
# else
# include <sys/types.h>
typedef ssize_t z_ssize_t;
# endif
#endif
/* Maximum value for memLevel in deflateInit2 */ /* Maximum value for memLevel in deflateInit2 */
#ifndef MAX_MEM_LEVEL #ifndef MAX_MEM_LEVEL
# ifdef MAXSEG_64K # ifdef MAXSEG_64K