[or-cvs] Define LONG_MAX and UINT_MAX when they are missing
Nick Mathewson
nickm at seul.org
Wed Aug 25 19:16:20 UTC 2004
Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv29009/src/common
Modified Files:
torint.h util.c
Log Message:
Define LONG_MAX and UINT_MAX when they are missing
Index: torint.h
===================================================================
RCS file: /home/or/cvsroot/src/common/torint.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- torint.h 10 May 2004 07:54:13 -0000 1.9
+++ torint.h 25 Aug 2004 19:16:18 -0000 1.10
@@ -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 @@
#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 */
/*
Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.129
retrieving revision 1.130
diff -u -d -r1.129 -r1.130
--- util.c 25 Aug 2004 17:31:46 -0000 1.129
+++ util.c 25 Aug 2004 19:16:18 -0000 1.130
@@ -874,12 +874,6 @@
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;
More information about the tor-commits
mailing list