From 74eb3f2af140700515f7bafd2aaea98307b80471 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 8 Jan 2006 00:09:49 +0000 Subject: r12761: get the TIME_T_MIN and TIME_T_MAX right again, merging from samba3 was a bad idea... as in samba4 we use TIME_T_MIN = 0 (maybe we should do this in samba3 too) because negativ values mean error. but still restrict TIME_T_MAX to INT32_MAX, to not overflow gmtime() on 64 bit systems, is this behavior documented somewhere? metze (This used to be commit 333b1b8c4885c47a0d14d83896fce6740fa4d663) --- source4/lib/time.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'source4') diff --git a/source4/lib/time.c b/source4/lib/time.c index 65e9fc85cb..eb42d2963e 100644 --- a/source4/lib/time.c +++ b/source4/lib/time.c @@ -27,14 +27,26 @@ #define CHAR_BIT 8 #endif +/* The extra casts work around common compiler bugs. */ +#define _TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) +/* The outer cast is needed to work around a bug in Cray C 5.0.3.0. + It is necessary at least when t == time_t. */ +#define _TYPE_MINIMUM(t) ((t) (_TYPE_SIGNED (t) \ + ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0)) +#define _TYPE_MAXIMUM(t) ((t) (~ (t) 0 - _TYPE_MINIMUM (t))) + #ifndef TIME_T_MIN -#define TIME_T_MIN ((time_t)0 < (time_t) -1 ? (time_t) 0 \ - : ~ (time_t) 0 << (sizeof (time_t) * CHAR_BIT - 1)) +/* we use 0 here, because (time_t)-1 means error */ +#define TIME_T_MIN 0 #endif #ifndef TIME_T_MAX -#define TIME_T_MAX MIN(INT32_MAX,(~ (time_t) 0 - TIME_T_MIN)) +/* + * we use the INT32_MAX here as on 64 bit systems, + * gmtime() fails with INT64_MAX + */ +#define TIME_T_MAX MIN(INT32_MAX,_TYPE_MAXIMUM(time_t)) #endif - + /******************************************************************* External access to time_t_min and time_t_max. ********************************************************************/ -- cgit