diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-08-25 19:16:18 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-08-25 19:16:18 +0000 |
commit | 31b81650b7eaf7dfec2cd1cf76755e9383011301 (patch) | |
tree | f3ba174f2193d364436229443b25ef53f02b1b6e /src/common | |
parent | 571176d2636e4f4803d48530d312611c16e393df (diff) | |
download | tor-31b81650b7eaf7dfec2cd1cf76755e9383011301.tar tor-31b81650b7eaf7dfec2cd1cf76755e9383011301.tar.gz |
Define LONG_MAX and UINT_MAX when they are missing
svn:r2317
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/torint.h | 39 | ||||
-rw-r--r-- | src/common/util.c | 6 |
2 files changed, 39 insertions, 6 deletions
diff --git a/src/common/torint.h b/src/common/torint.h index 07e291e51..8018fd889 100644 --- a/src/common/torint.h +++ b/src/common/torint.h @@ -18,6 +18,20 @@ #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> #endif +#ifdef HAVE_LIMITS_H +#include <limits.h> +#endif +#ifdef HAVE_SYS_LIMITS_H +#include <sys/limits.h> +#endif +#ifdef HAVE_MACHINE_LIMITS_H +#ifndef __FreeBSD__ + /* FreeBSD has a bug where it complains that this file is obsolete, + and I should migrate to using sys/limits. It complains even when + I include both. */ +#include <machine/limits.h> +#endif +#endif #if (SIZEOF_INT8_T != 0) @@ -180,6 +194,31 @@ typedef uint32_t uintptr_t; #error "Missing type uint64_t" #endif +/* XXXX This assumes a sane (2's-complement) representation. But if you + * aren't 2's complement, and you don't define LONG_MAX, then you're so + * bizarre that I want nothing to do with you. */ +#ifndef LONG_MAX +#if (SIZEOF_LONG == 4) +#define LONG_MAX 0x7fffffffL +#elif (SIZEOF_LONG == 8) +#define LONG_MAX 0x7fffffffffffffffL +#else +#error "Can't define LONG_MAX" +#endif +#endif + +#ifndef UINT_MAX +#if (SIZEOF_INT == 2) +#define UINT_MAX 0xffffu +#elif (SIZEOF_INT == 4) +#define UINT_MAX 0xffffffffu +#elif (SIZEOF_INT == 8) +#define UINT_MAX 0xffffffffffffffffu +#else +#error "Can't define UINT_MAX" +#endif +#endif + #endif /* __TORINT_H */ /* diff --git a/src/common/util.c b/src/common/util.c index 36a8048d2..4886f9b10 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -874,12 +874,6 @@ tv_udiff(struct timeval *start, struct timeval *end) long udiff; long secdiff = end->tv_sec - start->tv_sec; -/* XXX some SunOS machines don't have LONG_MAX defined in the includes - * we use. Surely there is a better fix... */ -#ifndef LONG_MAX -#define LONG_MAX 2147483647L -#endif - if (secdiff+1 > LONG_MAX/1000000) { log_fn(LOG_WARN, "comparing times too far apart."); return LONG_MAX; |