From 19c5c1d52fe2da201828740511b21bf6b07df18a Mon Sep 17 00:00:00 2001 From: hniksic Date: Mon, 26 Jun 2006 11:31:28 -0700 Subject: [PATCH] [svn] Allow 64-bit wgint without LFS. --- configure.in | 2 +- src/ChangeLog | 5 ++++ src/cmpt.c | 2 -- src/mswindows.h | 1 - src/sysdep.h | 9 ++---- src/wget.h | 73 ++++++++++++++++++++++++++++++++++--------------- 6 files changed, 59 insertions(+), 33 deletions(-) diff --git a/configure.in b/configure.in index 436efc99..529d16b1 100644 --- a/configure.in +++ b/configure.in @@ -189,7 +189,7 @@ dnl Checks for non-universal or system-specific types. dnl AC_TYPE_SIZE_T AC_TYPE_PID_T -AC_CHECK_TYPES([uint32_t, uintptr_t]) +AC_CHECK_TYPES([uint32_t, uintptr_t, int64_t]) AC_CHECK_TYPES(sig_atomic_t, [], [], [ #include #include diff --git a/src/ChangeLog b/src/ChangeLog index e17229eb..51c194f8 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2006-06-26 Hrvoje Niksic + + * wget.h (wgint): Typedef to any 64-bit (or larger) type we can + find, not necessarily off_t or long. + 2006-06-26 Hrvoje Niksic * cmpt.c (strtoll): Check for overflow and underflow without diff --git a/src/cmpt.c b/src/cmpt.c index aed889f1..a6b26073 100644 --- a/src/cmpt.c +++ b/src/cmpt.c @@ -1315,8 +1315,6 @@ char_value (char c, int base) return value; } -#define TYPE_MAXIMUM(t) ((t) (~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) - #define STRTOLL_MAX TYPE_MAXIMUM (strtoll_type) /* This definition assumes two's complement arithmetic */ #define STRTOLL_MIN (-STRTOLL_MAX - 1) diff --git a/src/mswindows.h b/src/mswindows.h index 8b9330b0..c61c56ed 100644 --- a/src/mswindows.h +++ b/src/mswindows.h @@ -84,7 +84,6 @@ so, delete this exception statement from your version. */ /* Define a wgint type under Windows. */ typedef __int64 wgint; #define SIZEOF_WGINT 8 -#define WGINT_MAX LL (9223372036854775807) /* str_to_wgint is a function with the semantics of strtol[l], but which works on wgint. */ diff --git a/src/sysdep.h b/src/sysdep.h index 38963901..9ac67a8e 100644 --- a/src/sysdep.h +++ b/src/sysdep.h @@ -112,13 +112,8 @@ typedef unsigned char _Bool; # define CHAR_BIT 8 #endif -/* Used by wget.h to define SIZEOF_WGINT. */ -#ifndef LONG_MAX -# define LONG_MAX ((long) ~((unsigned long)1 << (CHAR_BIT * sizeof (long) - 1))) -#endif -#ifndef LLONG_MAX -# define LLONG_MAX ((long long) ~((unsigned long long)1 << (CHAR_BIT * sizeof (long long) - 1))) -#endif +/* From gnulib, simplified to assume a signed type. */ +#define TYPE_MAXIMUM(t) ((t) (~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) /* These are defined in cmpt.c if missing, so we must declare them. */ diff --git a/src/wget.h b/src/wget.h index d0303e40..ee27b8f1 100644 --- a/src/wget.h +++ b/src/wget.h @@ -119,31 +119,60 @@ so, delete this exception statement from your version. */ #define DEBUGP(args) do { IF_DEBUG { debug_logprintf args; } } while (0) -/* Define an integer type that works for file sizes, content lengths, - and such. Normally we could just use off_t, but off_t is always - 32-bit on Windows. */ - -#ifndef WINDOWS -typedef off_t wgint; +/* Pick an integer type large enough for file sizes, content lengths, + and such. Because today's files can be very large, it should be a + signed integer at least 64 bits wide. This can't be typedeffed to + off_t because: a) off_t is always 32-bit on Windows, and b) we + don't necessarily want to tie having a 64-bit type for internal + calculations to having LFS support. */ + +#ifdef WINDOWS + /* nothing to do, see mswindows.h */ +#elif SIZEOF_LONG >= 8 + /* long is large enough, so use it. */ + typedef long wgint; +# define SIZEOF_WGINT SIZEOF_LONG +#elif SIZEOF_LONG_LONG >= 8 + /* long long is large enough and available, use that */ + typedef long long wgint; +# define SIZEOF_WGINT SIZEOF_LONG_LONG +#elif HAVE_INT64_T + typedef int64_t wgint; +# define SIZEOF_WGINT 8 +#elif SIZEOF_OFF_T >= 8 + /* In case off_t is typedeffed to a large non-standard type that our + tests don't find. */ + typedef off_t wgint; # define SIZEOF_WGINT SIZEOF_OFF_T +#else + /* Fall back to using long, which is always available and in most + cases large enough. */ +typedef long off_t; +# define SIZEOF_WGINT SIZEOF_LONG +#endif -/* Pick the strtol-like function that will work with wgint. */ -# if SIZEOF_WGINT == SIZEOF_LONG -# define str_to_wgint strtol -# define WGINT_MAX LONG_MAX -# else -# define WGINT_MAX LLONG_MAX -# ifdef HAVE_STRTOLL -# define str_to_wgint strtoll -# elif defined HAVE_STRTOIMAX /* HPUX 11.0 has strtoimax, but no strtoll */ -# define str_to_wgint strtoimax -# else -# define str_to_wgint strtoll -# define NEED_STRTOLL -# define strtoll_type long long -# endif +/* Pick a strtol-compatible function that will work with wgint. The + choices are strtol, strtoll, or our own implementation of strtoll + in cmpt.c, activated with NEED_STRTOLL. */ + +#ifdef WINDOWS + /* nothing to do, see mswindows.h */ +#elif SIZEOF_WGINT == SIZEOF_LONG +# define str_to_wgint strtol +#elif SIZEOF_WGINT == SIZEOF_LONG_LONG +# define str_to_wgint strtoll +# ifndef HAVE_STRTOLL +# define NEED_STRTOLL +# define strtoll_type long long # endif -#endif /* not WINDOWS */ +#else + /* wgint has a strange size; synthesize strtoll and use it. */ +# define str_to_wgint strtoll +# define NEED_STRTOLL +# define strtoll_type wgint +#endif + +#define WGINT_MAX TYPE_MAXIMUM (wgint) /* Declare our strtoll replacement. */ #ifdef NEED_STRTOLL -- 2.39.2