diff options
author | Andrew Tridgell <tridge@samba.org> | 2004-05-25 13:57:39 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:56:14 -0500 |
commit | 579c13da43d5b40ac6d6c1436399fbc1d8dfd054 (patch) | |
tree | 42299570746f2d7f80356b689cb15e3db6c53d3c /source4/lib/time.c | |
parent | 81e8de9ca85fe9a6658beb1dab0d231c13cda063 (diff) | |
download | samba-579c13da43d5b40ac6d6c1436399fbc1d8dfd054.tar.gz samba-579c13da43d5b40ac6d6c1436399fbc1d8dfd054.tar.xz samba-579c13da43d5b40ac6d6c1436399fbc1d8dfd054.zip |
r873: converted samba4 to use real 64 bit integers instead of
structures. This was suggested by metze recently.
I checked on the build farm and all the machines we have support 64
bit ints, and support the LL suffix for 64 bit constants. I suspect
some won't support strtoll() and related functions, so we will
probably need replacements for those.
(This used to be commit 9a9244a1c66654c12abe4379661cba83a73c4c21)
Diffstat (limited to 'source4/lib/time.c')
-rw-r--r-- | source4/lib/time.c | 99 |
1 files changed, 23 insertions, 76 deletions
diff --git a/source4/lib/time.c b/source4/lib/time.c index ba650668c5..e3811c884e 100644 --- a/source4/lib/time.c +++ b/source4/lib/time.c @@ -23,11 +23,10 @@ #include "includes.h" #ifndef TIME_T_MIN -#define TIME_T_MIN ((time_t)0 < (time_t) -1 ? (time_t) 0 \ - : ~ (time_t) 0 << (sizeof (time_t) * 8 - 1)) +#define TIME_T_MIN 0 #endif #ifndef TIME_T_MAX -#define TIME_T_MAX (~ (time_t) 0 - TIME_T_MIN) +#define TIME_T_MAX (~(time_t)0) #endif /******************************************************************* @@ -84,35 +83,23 @@ int get_time_zone(time_t t) return tm_diff(&tm_utc,tm); } -#define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60)) +#define TIME_FIXUP_CONSTANT 11644473600LL /**************************************************************************** interpret an 8 byte "filetime" structure to a time_t It's originally in "100ns units since jan 1st 1601" ****************************************************************************/ -time_t nt_time_to_unix(const NTTIME *nt) +time_t nt_time_to_unix(NTTIME nt) { - double d; - time_t ret; + nt += 1000*1000*10/2; + nt /= 1000*1000*10; + nt -= TIME_FIXUP_CONSTANT; - if (nt->high == 0) { + if (TIME_T_MIN >= nt || nt >= TIME_T_MAX) { return 0; } - d = ((double)nt->high)*4.0*(double)(1<<30); - d += (nt->low&0xFFF00000); - d *= 1.0e-7; - - /* now adjust by 369 years to make the secs since 1970 */ - d -= TIME_FIXUP_CONSTANT; - - if (TIME_T_MIN >= d || d >= TIME_T_MAX) { - return 0; - } - - ret = (time_t)(d+0.5); - - return ret; + return (time_t)nt; } @@ -122,30 +109,22 @@ This takes GMT as input ****************************************************************************/ void unix_to_nt_time(NTTIME *nt, time_t t) { - double d; + uint64_t t2; - if (t==0) { - nt->low = 0; - nt->high = 0; - return; - } - if (t == TIME_T_MAX) { - nt->low = 0xffffffff; - nt->high = 0x7fffffff; + if (t == (time_t)-1) { + *nt = (NTTIME)-1LL; return; } - if (t == -1) { - nt->low = 0xffffffff; - nt->high = 0xffffffff; + if (t == 0) { + *nt = 0; return; } - d = (double)(t); - d += TIME_FIXUP_CONSTANT; - d *= 1.0e7; + t2 = t; + t2 += TIME_FIXUP_CONSTANT; + t2 *= 1000*1000*10; - nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30)))); - nt->low = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30)); + *nt = t2; } @@ -390,18 +369,10 @@ char *timestring(TALLOC_CTX *mem_ctx, time_t t) return TimeBuf; } -/**************************************************************************** -check if NTTIME is 0 -****************************************************************************/ -BOOL nt_time_is_zero(NTTIME *nt) -{ - return (nt->high==0); -} - /* return a talloced string representing a NTTIME for human consumption */ -const char *nt_time_string(TALLOC_CTX *mem_ctx, const NTTIME *nt) +const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt) { time_t t = nt_time_to_unix(nt); return talloc_strdup(mem_ctx, timestring(mem_ctx, t)); @@ -411,10 +382,9 @@ const char *nt_time_string(TALLOC_CTX *mem_ctx, const NTTIME *nt) /* put a NTTIME into a packet */ -void push_nttime(void *base, uint16 offset, NTTIME *t) +void push_nttime(void *base, uint16 offset, NTTIME t) { - SIVAL(base, offset, t->low); - SIVAL(base, offset+4, t->high); + SBVAL(base, offset, t); } /* @@ -422,30 +392,7 @@ void push_nttime(void *base, uint16 offset, NTTIME *t) */ NTTIME pull_nttime(void *base, uint16 offset) { - NTTIME ret; - ret.low = IVAL(base, offset); - ret.high = IVAL(base, offset+4); - return ret; -} - -/* - convert a NTTIME to a double in 100-nano-seconds since 1601 -*/ -double nttime_to_double_nt(NTTIME t) -{ - const double t32 = 4294967296.0; - return t.high*t32 + t.low; -} - -/* - convert a double in 100-nano-seconds since 1601 to a NTTIME -*/ -NTTIME nttime_from_double_nt(double t) -{ - const double t32 = 4294967296.0; - NTTIME ret; - ret.high = t / t32; - ret.low = t - (ret.high*t32); + NTTIME ret = BVAL(base, offset); return ret; } @@ -454,5 +401,5 @@ NTTIME nttime_from_double_nt(double t) */ NTTIME nttime_from_string(const char *s) { - return nttime_from_double_nt(strtod(s, NULL)); + return strtoull(s, NULL, 0); } |