From c15c0f2a47caa61f0575a63d88d1481d34530643 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 May 2007 23:38:56 +0000 Subject: r23005: If we're running on a system where time_t is 8 bytes we have to take care to preserve the "special" values for Windows of 0x80000000 and 0x7FFFFFFF when casting between time_t and uint32. Add conversion functions (and use them). Jeremy. (This used to be commit 4e1a0b2549f7c11326deed2801de19564af0f16a) --- source3/lib/time.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index e98f8232ab..ba158fe1ae 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -554,6 +554,37 @@ NTTIME timeval_to_nttime(const struct timeval *tv) ((TIME_FIXUP_CONSTANT_INT + (uint64_t)tv->tv_sec) * 1000000)); } +/************************************************************** + Handle conversions between time_t and uint32, taking care to + preserve the "special" values. +**************************************************************/ + +uint32 convert_time_t_to_uint32(time_t t) +{ +#if (defined(SIZEOF_TIME_T) && (SIZEOF_TIME_T == 8)) + /* time_t is 64-bit. */ + if (t == 0x8000000000000000LL) { + return 0x80000000; + } else if (t == 0x7FFFFFFFFFFFFFFFLL) { + return 0x7FFFFFFF; + } +#endif + return (uint32)t; +} + +time_t convert_uint32_to_time_t(uint32 u) +{ +#if (defined(SIZEOF_TIME_T) && (SIZEOF_TIME_T == 8)) + /* time_t is 64-bit. */ + if (u == 0x80000000) { + return (time_t)0x8000000000000000LL; + } else if (u == 0x7FFFFFFF) { + return (time_t)0x7FFFFFFFFFFFFFFFLL) { + } +#endif + return (time_t)u; +} + /******************************************************************* Yield the difference between *A and *B, in seconds, ignoring leap seconds. ********************************************************************/ -- cgit