From d630105b563aca913750200ea6e9ad17241ac51d Mon Sep 17 00:00:00 2001 From: Rafal Szczesniak Date: Mon, 18 Sep 2006 17:32:13 +0000 Subject: r18614: a bit of work done while on the plane. a new function converting NTTIME to struct timeval rafal (This used to be commit e9ebbb8661ac6efc5bf07798a64cdb9f7c7eea50) --- source4/lib/util/time.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source4') diff --git a/source4/lib/util/time.c b/source4/lib/util/time.c index 6ad3a229e3..d3cdecdfe3 100644 --- a/source4/lib/util/time.c +++ b/source4/lib/util/time.c @@ -566,6 +566,28 @@ _PUBLIC_ NTTIME timeval_to_nttime(const struct timeval *tv) ((TIME_FIXUP_CONSTANT + (uint64_t)tv->tv_sec) * 1000000)); } +/** + convert a NTTIME to a timeval +*/ +_PUBLIC_ void nttime_to_timeval(struct timeval *tv, NTTIME t) +{ + if (tv == NULL) return; + + t += 10/2; + t /= 10; + t -= TIME_FIXUP_CONSTANT*1000*1000; + + tv->tv_sec = t / 1000000; + + if (TIME_T_MIN > tv->tv_sec || tv->tv_sec > TIME_T_MAX) { + tv->tv_sec = 0; + tv->tv_usec = 0; + return; + } + + tv->tv_usec = t - tv->tv_sec*1000000; +} + /******************************************************************* yield the difference between *A and *B, in seconds, ignoring leap seconds ********************************************************************/ -- cgit