Fix logic to set TIME_T_MAX; apparently, everybody had thought of the prospect of a signed time_t but me.

svn:r4675
This commit is contained in:
Nick Mathewson 2005-07-25 18:10:08 +00:00
parent a32f936346
commit 48787c839e
2 changed files with 37 additions and 2 deletions

View File

@ -335,6 +335,17 @@ AC_CHECK_SIZEOF(long long)
AC_CHECK_SIZEOF(__int64)
AC_CHECK_SIZEOF(void *)
AC_CHECK_SIZEOF(time_t)
AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
AC_TRY_RUN([
int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }],
tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes)
])
if test $tor_cv_time_t_signed = yes; then
AC_DEFINE([TIME_T_IS_SIGNED], 1,
[Define to 1 iff time_t is signed])
fi
AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>

View File

@ -224,6 +224,16 @@ typedef uint32_t uintptr_t;
#endif
#endif
#ifndef INT_MAX
#if (SIZEOF_INT == 4)
#define INT_MAX 0x7fffffffL
#elif (SIZEOF_INT == 8)
#define INT_MAX 0x7fffffffffffffffL
#else
#error "Can't define INT_MAX"
#endif
#endif
#ifndef UINT_MAX
#if (SIZEOF_INT == 2)
#define UINT_MAX 0xffffu
@ -237,14 +247,28 @@ typedef uint32_t uintptr_t;
#endif
#ifndef TIME_MAX
#ifdef TIME_T_IS_SIGNED
#if (SIZEOF_TIME_T == SIZEOF_INT)
#define TIME_MAX ((time_t)INT_MAX)
#elif (SIZEOF_TIME_T == SIZEOF_LONG)
#define TIME_MAX ((time_t)LONG_MAX)
#else
#error "Can't define (signed) TIME_MAX"
#endif
#else
/* Unsigned case */
#if (SIZEOF_TIME_T == 4)
#define TIME_MAX ((time_t)UINT32_MAX)
#elif (SIZEOF_TIME_T == 8)
#define TIME_MAX ((time_t)UINT64_MAX)
#else
#error "Can't define TIME_MAX"
#endif
#error "Can't define (unsigned) TIME_MAX"
#endif
#endif /* time_t_is_signed */
#endif /* ifndef(TIME_MAX) */
/* Any size_t larger than this amount is likely to be an underflow. */
#define SIZE_T_CEILING (sizeof(char)<<(sizeof(size_t)*8 - 1))