summaryrefslogtreecommitdiff
path: root/source4/lib/time.c
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2006-01-08 00:09:49 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:49:51 -0500
commit74eb3f2af140700515f7bafd2aaea98307b80471 (patch)
treeae689c921b3785ab6cd9bbb1de277adc08b53534 /source4/lib/time.c
parentda8151ae9f42b86868fa2ad3fc3825f2285a2fb4 (diff)
downloadsamba-74eb3f2af140700515f7bafd2aaea98307b80471.tar.gz
samba-74eb3f2af140700515f7bafd2aaea98307b80471.tar.bz2
samba-74eb3f2af140700515f7bafd2aaea98307b80471.zip
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)
Diffstat (limited to 'source4/lib/time.c')
-rw-r--r--source4/lib/time.c20
1 files changed, 16 insertions, 4 deletions
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.
********************************************************************/