1998-12-12 20:48:14 +00:00
|
|
|
/*
|
2012-09-26 23:46:13 +00:00
|
|
|
* Copyright (C) 2004, 2006-2009, 2012 Internet Systems Consortium, Inc. ("ISC")
|
2004-03-05 05:14:21 +00:00
|
|
|
* Copyright (C) 1998-2001, 2003 Internet Software Consortium.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2007-06-18 23:47:57 +00:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
1998-12-12 20:48:14 +00:00
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2004-03-05 05:14:21 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
1998-12-12 20:48:14 +00:00
|
|
|
*/
|
1998-10-23 05:45:44 +00:00
|
|
|
|
2009-08-14 07:51:08 +00:00
|
|
|
/* $Id: time.c,v 1.52 2009/08/14 07:51:08 marka Exp $ */
|
2000-06-22 22:00:42 +00:00
|
|
|
|
1998-12-12 19:25:20 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
189. [func] isc_time_secondsastimet(), a new function, will ensure
that the number of seconds in an isc_time_t does not
exceed the range of a time_t, or return ISC_R_RANGE.
Similarly, isc_time_now(), isc_time_nowplusinterval(),
isc_time_add() and isc_time_subtract() now check the
range for overflow/underflow. In the case of
isc_time_subtract, this changed a calling requirement
(ie, something that could generate an assertion)
into merely a condition that returns an error result.
isc_time_add() and isc_time_subtract() were void-
valued before but now return isc_result_t.
The seconds member isc_time_t on Unix platforms was changed from time_t
to unsigned int.
unix/time.c now uses macros for nanoseconds per second, nanoseconds per
microsecond and microseconds per second to make sure that the right
number of zeros appears each place the constant is used.
unix/time.c functions which take initialized isc_(interval|time)_t arguments
INSIST() that the nanoseconds value is less than one full second.
unix/time.c's isc_time_microdiff was broken because it did multiplication and
addition with unsigned integers and attempted to set them a 64 bit int to
avoid overflow, but C's ints don't promote to 64 bits on machines that only
have 32 bit longs. Fixed.
Added all the pertinent documentation to time.h.
2000-05-18 17:08:32 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
1998-10-23 05:45:44 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
1998-10-23 06:02:07 +00:00
|
|
|
|
|
|
|
#include <windows.h>
|
1998-10-23 05:45:44 +00:00
|
|
|
|
|
|
|
#include <isc/assertions.h>
|
|
|
|
#include <isc/time.h>
|
2001-07-06 05:08:39 +00:00
|
|
|
#include <isc/util.h>
|
1998-10-23 05:45:44 +00:00
|
|
|
|
2000-03-10 17:50:36 +00:00
|
|
|
/*
|
189. [func] isc_time_secondsastimet(), a new function, will ensure
that the number of seconds in an isc_time_t does not
exceed the range of a time_t, or return ISC_R_RANGE.
Similarly, isc_time_now(), isc_time_nowplusinterval(),
isc_time_add() and isc_time_subtract() now check the
range for overflow/underflow. In the case of
isc_time_subtract, this changed a calling requirement
(ie, something that could generate an assertion)
into merely a condition that returns an error result.
isc_time_add() and isc_time_subtract() were void-
valued before but now return isc_result_t.
The seconds member isc_time_t on Unix platforms was changed from time_t
to unsigned int.
unix/time.c now uses macros for nanoseconds per second, nanoseconds per
microsecond and microseconds per second to make sure that the right
number of zeros appears each place the constant is used.
unix/time.c functions which take initialized isc_(interval|time)_t arguments
INSIST() that the nanoseconds value is less than one full second.
unix/time.c's isc_time_microdiff was broken because it did multiplication and
addition with unsigned integers and attempted to set them a 64 bit int to
avoid overflow, but C's ints don't promote to 64 bits on machines that only
have 32 bit longs. Fixed.
Added all the pertinent documentation to time.h.
2000-05-18 17:08:32 +00:00
|
|
|
* struct FILETIME uses "100-nanoseconds intervals".
|
2000-03-10 17:50:36 +00:00
|
|
|
* NS / S = 1000000000 (10^9).
|
|
|
|
* While it is reasonably obvious that this makes the needed
|
|
|
|
* conversion factor 10^7, it is coded this way for additional clarity.
|
|
|
|
*/
|
|
|
|
#define NS_PER_S 1000000000
|
|
|
|
#define NS_INTERVAL 100
|
|
|
|
#define INTERVALS_PER_S (NS_PER_S / NS_INTERVAL)
|
2001-07-06 05:08:39 +00:00
|
|
|
#define UINT64_MAX _UI64_MAX
|
|
|
|
|
|
|
|
/***
|
|
|
|
*** Absolute Times
|
|
|
|
***/
|
|
|
|
|
2012-09-26 14:58:53 +10:00
|
|
|
static const isc_time_t epoch = { { 0, 0 } };
|
|
|
|
LIBISC_EXTERNAL_DATA const isc_time_t * const isc_time_epoch = &epoch;
|
2001-07-06 05:08:39 +00:00
|
|
|
|
1998-10-26 23:07:57 +00:00
|
|
|
/***
|
|
|
|
*** Intervals
|
|
|
|
***/
|
|
|
|
|
2012-09-26 14:58:53 +10:00
|
|
|
static const isc_interval_t zero_interval = { 0 };
|
|
|
|
LIBISC_EXTERNAL_DATA const isc_interval_t * const isc_interval_zero = &zero_interval;
|
1999-10-17 22:26:09 +00:00
|
|
|
|
1998-10-26 23:07:57 +00:00
|
|
|
void
|
2001-07-09 21:06:30 +00:00
|
|
|
isc_interval_set(isc_interval_t *i, unsigned int seconds,
|
|
|
|
unsigned int nanoseconds)
|
|
|
|
{
|
1998-10-26 23:07:57 +00:00
|
|
|
REQUIRE(i != NULL);
|
2001-07-06 05:08:39 +00:00
|
|
|
REQUIRE(nanoseconds < NS_PER_S);
|
1998-10-26 23:07:57 +00:00
|
|
|
|
2008-08-29 03:57:38 +00:00
|
|
|
/*
|
|
|
|
* This rounds nanoseconds up not down.
|
|
|
|
*/
|
2000-03-10 17:50:36 +00:00
|
|
|
i->interval = (LONGLONG)seconds * INTERVALS_PER_S
|
2008-08-29 03:57:38 +00:00
|
|
|
+ (nanoseconds + NS_INTERVAL - 1) / NS_INTERVAL;
|
1998-10-26 23:07:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_boolean_t
|
2001-10-08 18:58:11 +00:00
|
|
|
isc_interval_iszero(const isc_interval_t *i) {
|
1998-10-26 23:07:57 +00:00
|
|
|
REQUIRE(i != NULL);
|
|
|
|
if (i->interval == 0)
|
|
|
|
return (ISC_TRUE);
|
|
|
|
|
|
|
|
return (ISC_FALSE);
|
|
|
|
}
|
|
|
|
|
2008-09-08 06:53:10 +00:00
|
|
|
void
|
|
|
|
isc_time_set(isc_time_t *t, unsigned int seconds, unsigned int nanoseconds) {
|
|
|
|
SYSTEMTIME epoch = { 1970, 1, 4, 1, 0, 0, 0, 0 };
|
|
|
|
FILETIME temp;
|
|
|
|
ULARGE_INTEGER i1;
|
|
|
|
|
|
|
|
REQUIRE(t != NULL);
|
|
|
|
REQUIRE(nanoseconds < NS_PER_S);
|
2008-09-08 23:47:10 +00:00
|
|
|
|
2008-09-08 06:53:10 +00:00
|
|
|
SystemTimeToFileTime(&epoch, &temp);
|
2008-09-08 23:47:10 +00:00
|
|
|
|
2008-09-08 06:53:10 +00:00
|
|
|
i1.LowPart = t->absolute.dwLowDateTime;
|
|
|
|
i1.HighPart = t->absolute.dwHighDateTime;
|
|
|
|
|
|
|
|
i1.QuadPart += (unsigned __int64)nanoseconds/100;
|
2008-09-08 08:28:08 +00:00
|
|
|
i1.QuadPart += (unsigned __int64)seconds*10000000;
|
2008-09-08 06:53:10 +00:00
|
|
|
|
|
|
|
t->absolute.dwLowDateTime = i1.LowPart;
|
|
|
|
t->absolute.dwHighDateTime = i1.HighPart;
|
|
|
|
}
|
|
|
|
|
1998-10-26 23:07:57 +00:00
|
|
|
void
|
1999-09-23 18:03:39 +00:00
|
|
|
isc_time_settoepoch(isc_time_t *t) {
|
1998-10-26 23:07:57 +00:00
|
|
|
REQUIRE(t != NULL);
|
|
|
|
|
2001-09-01 00:55:27 +00:00
|
|
|
t->absolute.dwLowDateTime = 0;
|
|
|
|
t->absolute.dwHighDateTime = 0;
|
1998-10-26 23:07:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_boolean_t
|
2001-10-08 18:58:11 +00:00
|
|
|
isc_time_isepoch(const isc_time_t *t) {
|
1998-10-26 23:07:57 +00:00
|
|
|
REQUIRE(t != NULL);
|
|
|
|
|
2001-09-01 00:55:27 +00:00
|
|
|
if (t->absolute.dwLowDateTime == 0 &&
|
|
|
|
t->absolute.dwHighDateTime == 0)
|
1998-10-26 23:07:57 +00:00
|
|
|
return (ISC_TRUE);
|
|
|
|
|
|
|
|
return (ISC_FALSE);
|
|
|
|
}
|
|
|
|
|
1999-09-23 18:03:39 +00:00
|
|
|
isc_result_t
|
|
|
|
isc_time_now(isc_time_t *t) {
|
1998-10-23 05:45:44 +00:00
|
|
|
REQUIRE(t != NULL);
|
1998-10-23 06:02:07 +00:00
|
|
|
|
1998-10-27 03:12:07 +00:00
|
|
|
GetSystemTimeAsFileTime(&t->absolute);
|
1998-10-23 06:02:07 +00:00
|
|
|
|
1998-10-23 05:45:44 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
1999-09-23 18:03:39 +00:00
|
|
|
isc_result_t
|
2001-10-08 18:58:11 +00:00
|
|
|
isc_time_nowplusinterval(isc_time_t *t, const isc_interval_t *i) {
|
1999-09-23 18:03:39 +00:00
|
|
|
ULARGE_INTEGER i1;
|
1998-10-26 23:07:57 +00:00
|
|
|
|
1999-09-23 18:03:39 +00:00
|
|
|
REQUIRE(t != NULL);
|
|
|
|
REQUIRE(i != NULL);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-09-23 18:03:39 +00:00
|
|
|
GetSystemTimeAsFileTime(&t->absolute);
|
|
|
|
|
|
|
|
i1.LowPart = t->absolute.dwLowDateTime;
|
|
|
|
i1.HighPart = t->absolute.dwHighDateTime;
|
|
|
|
|
2001-07-06 05:08:39 +00:00
|
|
|
if (UINT64_MAX - i1.QuadPart < (unsigned __int64)i->interval)
|
189. [func] isc_time_secondsastimet(), a new function, will ensure
that the number of seconds in an isc_time_t does not
exceed the range of a time_t, or return ISC_R_RANGE.
Similarly, isc_time_now(), isc_time_nowplusinterval(),
isc_time_add() and isc_time_subtract() now check the
range for overflow/underflow. In the case of
isc_time_subtract, this changed a calling requirement
(ie, something that could generate an assertion)
into merely a condition that returns an error result.
isc_time_add() and isc_time_subtract() were void-
valued before but now return isc_result_t.
The seconds member isc_time_t on Unix platforms was changed from time_t
to unsigned int.
unix/time.c now uses macros for nanoseconds per second, nanoseconds per
microsecond and microseconds per second to make sure that the right
number of zeros appears each place the constant is used.
unix/time.c functions which take initialized isc_(interval|time)_t arguments
INSIST() that the nanoseconds value is less than one full second.
unix/time.c's isc_time_microdiff was broken because it did multiplication and
addition with unsigned integers and attempted to set them a 64 bit int to
avoid overflow, but C's ints don't promote to 64 bits on machines that only
have 32 bit longs. Fixed.
Added all the pertinent documentation to time.h.
2000-05-18 17:08:32 +00:00
|
|
|
return (ISC_R_RANGE);
|
|
|
|
|
1999-09-23 18:03:39 +00:00
|
|
|
i1.QuadPart += i->interval;
|
|
|
|
|
|
|
|
t->absolute.dwLowDateTime = i1.LowPart;
|
|
|
|
t->absolute.dwHighDateTime = i1.HighPart;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-10-08 18:58:11 +00:00
|
|
|
isc_time_compare(const isc_time_t *t1, const isc_time_t *t2) {
|
1998-10-23 05:45:44 +00:00
|
|
|
REQUIRE(t1 != NULL && t2 != NULL);
|
|
|
|
|
1998-10-27 03:12:07 +00:00
|
|
|
return ((int)CompareFileTime(&t1->absolute, &t2->absolute));
|
1998-10-23 05:45:44 +00:00
|
|
|
}
|
|
|
|
|
189. [func] isc_time_secondsastimet(), a new function, will ensure
that the number of seconds in an isc_time_t does not
exceed the range of a time_t, or return ISC_R_RANGE.
Similarly, isc_time_now(), isc_time_nowplusinterval(),
isc_time_add() and isc_time_subtract() now check the
range for overflow/underflow. In the case of
isc_time_subtract, this changed a calling requirement
(ie, something that could generate an assertion)
into merely a condition that returns an error result.
isc_time_add() and isc_time_subtract() were void-
valued before but now return isc_result_t.
The seconds member isc_time_t on Unix platforms was changed from time_t
to unsigned int.
unix/time.c now uses macros for nanoseconds per second, nanoseconds per
microsecond and microseconds per second to make sure that the right
number of zeros appears each place the constant is used.
unix/time.c functions which take initialized isc_(interval|time)_t arguments
INSIST() that the nanoseconds value is less than one full second.
unix/time.c's isc_time_microdiff was broken because it did multiplication and
addition with unsigned integers and attempted to set them a 64 bit int to
avoid overflow, but C's ints don't promote to 64 bits on machines that only
have 32 bit longs. Fixed.
Added all the pertinent documentation to time.h.
2000-05-18 17:08:32 +00:00
|
|
|
isc_result_t
|
2001-10-08 18:58:11 +00:00
|
|
|
isc_time_add(const isc_time_t *t, const isc_interval_t *i, isc_time_t *result)
|
|
|
|
{
|
2000-04-24 20:58:03 +00:00
|
|
|
ULARGE_INTEGER i1;
|
1998-10-27 03:12:07 +00:00
|
|
|
|
1998-10-26 23:07:57 +00:00
|
|
|
REQUIRE(t != NULL && i != NULL && result != NULL);
|
1998-10-23 05:45:44 +00:00
|
|
|
|
1998-10-27 03:12:07 +00:00
|
|
|
i1.LowPart = t->absolute.dwLowDateTime;
|
|
|
|
i1.HighPart = t->absolute.dwHighDateTime;
|
|
|
|
|
2001-07-06 05:08:39 +00:00
|
|
|
if (UINT64_MAX - i1.QuadPart < (unsigned __int64)i->interval)
|
189. [func] isc_time_secondsastimet(), a new function, will ensure
that the number of seconds in an isc_time_t does not
exceed the range of a time_t, or return ISC_R_RANGE.
Similarly, isc_time_now(), isc_time_nowplusinterval(),
isc_time_add() and isc_time_subtract() now check the
range for overflow/underflow. In the case of
isc_time_subtract, this changed a calling requirement
(ie, something that could generate an assertion)
into merely a condition that returns an error result.
isc_time_add() and isc_time_subtract() were void-
valued before but now return isc_result_t.
The seconds member isc_time_t on Unix platforms was changed from time_t
to unsigned int.
unix/time.c now uses macros for nanoseconds per second, nanoseconds per
microsecond and microseconds per second to make sure that the right
number of zeros appears each place the constant is used.
unix/time.c functions which take initialized isc_(interval|time)_t arguments
INSIST() that the nanoseconds value is less than one full second.
unix/time.c's isc_time_microdiff was broken because it did multiplication and
addition with unsigned integers and attempted to set them a 64 bit int to
avoid overflow, but C's ints don't promote to 64 bits on machines that only
have 32 bit longs. Fixed.
Added all the pertinent documentation to time.h.
2000-05-18 17:08:32 +00:00
|
|
|
return (ISC_R_RANGE);
|
|
|
|
|
2000-04-24 20:58:03 +00:00
|
|
|
i1.QuadPart += i->interval;
|
|
|
|
|
|
|
|
result->absolute.dwLowDateTime = i1.LowPart;
|
|
|
|
result->absolute.dwHighDateTime = i1.HighPart;
|
189. [func] isc_time_secondsastimet(), a new function, will ensure
that the number of seconds in an isc_time_t does not
exceed the range of a time_t, or return ISC_R_RANGE.
Similarly, isc_time_now(), isc_time_nowplusinterval(),
isc_time_add() and isc_time_subtract() now check the
range for overflow/underflow. In the case of
isc_time_subtract, this changed a calling requirement
(ie, something that could generate an assertion)
into merely a condition that returns an error result.
isc_time_add() and isc_time_subtract() were void-
valued before but now return isc_result_t.
The seconds member isc_time_t on Unix platforms was changed from time_t
to unsigned int.
unix/time.c now uses macros for nanoseconds per second, nanoseconds per
microsecond and microseconds per second to make sure that the right
number of zeros appears each place the constant is used.
unix/time.c functions which take initialized isc_(interval|time)_t arguments
INSIST() that the nanoseconds value is less than one full second.
unix/time.c's isc_time_microdiff was broken because it did multiplication and
addition with unsigned integers and attempted to set them a 64 bit int to
avoid overflow, but C's ints don't promote to 64 bits on machines that only
have 32 bit longs. Fixed.
Added all the pertinent documentation to time.h.
2000-05-18 17:08:32 +00:00
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
1998-10-23 05:45:44 +00:00
|
|
|
}
|
|
|
|
|
189. [func] isc_time_secondsastimet(), a new function, will ensure
that the number of seconds in an isc_time_t does not
exceed the range of a time_t, or return ISC_R_RANGE.
Similarly, isc_time_now(), isc_time_nowplusinterval(),
isc_time_add() and isc_time_subtract() now check the
range for overflow/underflow. In the case of
isc_time_subtract, this changed a calling requirement
(ie, something that could generate an assertion)
into merely a condition that returns an error result.
isc_time_add() and isc_time_subtract() were void-
valued before but now return isc_result_t.
The seconds member isc_time_t on Unix platforms was changed from time_t
to unsigned int.
unix/time.c now uses macros for nanoseconds per second, nanoseconds per
microsecond and microseconds per second to make sure that the right
number of zeros appears each place the constant is used.
unix/time.c functions which take initialized isc_(interval|time)_t arguments
INSIST() that the nanoseconds value is less than one full second.
unix/time.c's isc_time_microdiff was broken because it did multiplication and
addition with unsigned integers and attempted to set them a 64 bit int to
avoid overflow, but C's ints don't promote to 64 bits on machines that only
have 32 bit longs. Fixed.
Added all the pertinent documentation to time.h.
2000-05-18 17:08:32 +00:00
|
|
|
isc_result_t
|
2001-10-08 18:58:11 +00:00
|
|
|
isc_time_subtract(const isc_time_t *t, const isc_interval_t *i,
|
|
|
|
isc_time_t *result) {
|
2000-04-24 20:58:03 +00:00
|
|
|
ULARGE_INTEGER i1;
|
1998-10-27 03:12:07 +00:00
|
|
|
|
1998-10-26 23:07:57 +00:00
|
|
|
REQUIRE(t != NULL && i != NULL && result != NULL);
|
1998-10-27 03:12:07 +00:00
|
|
|
|
|
|
|
i1.LowPart = t->absolute.dwLowDateTime;
|
|
|
|
i1.HighPart = t->absolute.dwHighDateTime;
|
|
|
|
|
2001-07-06 05:08:39 +00:00
|
|
|
if (i1.QuadPart < (unsigned __int64) i->interval)
|
189. [func] isc_time_secondsastimet(), a new function, will ensure
that the number of seconds in an isc_time_t does not
exceed the range of a time_t, or return ISC_R_RANGE.
Similarly, isc_time_now(), isc_time_nowplusinterval(),
isc_time_add() and isc_time_subtract() now check the
range for overflow/underflow. In the case of
isc_time_subtract, this changed a calling requirement
(ie, something that could generate an assertion)
into merely a condition that returns an error result.
isc_time_add() and isc_time_subtract() were void-
valued before but now return isc_result_t.
The seconds member isc_time_t on Unix platforms was changed from time_t
to unsigned int.
unix/time.c now uses macros for nanoseconds per second, nanoseconds per
microsecond and microseconds per second to make sure that the right
number of zeros appears each place the constant is used.
unix/time.c functions which take initialized isc_(interval|time)_t arguments
INSIST() that the nanoseconds value is less than one full second.
unix/time.c's isc_time_microdiff was broken because it did multiplication and
addition with unsigned integers and attempted to set them a 64 bit int to
avoid overflow, but C's ints don't promote to 64 bits on machines that only
have 32 bit longs. Fixed.
Added all the pertinent documentation to time.h.
2000-05-18 17:08:32 +00:00
|
|
|
return (ISC_R_RANGE);
|
2000-04-24 20:58:03 +00:00
|
|
|
|
|
|
|
i1.QuadPart -= i->interval;
|
|
|
|
|
|
|
|
result->absolute.dwLowDateTime = i1.LowPart;
|
|
|
|
result->absolute.dwHighDateTime = i1.HighPart;
|
2001-07-06 05:08:39 +00:00
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
1998-10-23 05:45:44 +00:00
|
|
|
}
|
1998-10-26 23:07:57 +00:00
|
|
|
|
1999-10-09 02:39:53 +00:00
|
|
|
isc_uint64_t
|
2001-10-08 18:58:11 +00:00
|
|
|
isc_time_microdiff(const isc_time_t *t1, const isc_time_t *t2) {
|
1999-09-23 18:03:39 +00:00
|
|
|
ULARGE_INTEGER i1, i2;
|
1998-10-27 03:12:07 +00:00
|
|
|
LONGLONG i3;
|
|
|
|
|
1999-09-23 18:03:39 +00:00
|
|
|
REQUIRE(t1 != NULL && t2 != NULL);
|
|
|
|
|
|
|
|
i1.LowPart = t1->absolute.dwLowDateTime;
|
1998-10-27 03:12:07 +00:00
|
|
|
i1.HighPart = t1->absolute.dwHighDateTime;
|
1999-09-23 18:03:39 +00:00
|
|
|
i2.LowPart = t2->absolute.dwLowDateTime;
|
1998-10-27 03:12:07 +00:00
|
|
|
i2.HighPart = t2->absolute.dwHighDateTime;
|
|
|
|
|
|
|
|
if (i1.QuadPart <= i2.QuadPart)
|
|
|
|
return (0);
|
1999-09-23 18:03:39 +00:00
|
|
|
|
|
|
|
/*
|
1999-10-09 02:39:53 +00:00
|
|
|
* Convert to microseconds.
|
1999-09-23 18:03:39 +00:00
|
|
|
*/
|
1999-10-09 02:39:53 +00:00
|
|
|
i3 = (i1.QuadPart - i2.QuadPart) / 10;
|
1999-09-23 18:03:39 +00:00
|
|
|
|
1999-10-09 02:39:53 +00:00
|
|
|
return (i3);
|
1998-10-26 23:07:57 +00:00
|
|
|
}
|
2000-03-10 17:50:36 +00:00
|
|
|
|
2004-03-16 05:52:24 +00:00
|
|
|
isc_uint32_t
|
|
|
|
isc_time_seconds(const isc_time_t *t) {
|
2009-08-13 03:34:10 +00:00
|
|
|
SYSTEMTIME epoch = { 1970, 1, 4, 1, 0, 0, 0, 0 };
|
|
|
|
FILETIME temp;
|
|
|
|
ULARGE_INTEGER i1, i2;
|
|
|
|
LONGLONG i3;
|
2004-03-16 05:52:24 +00:00
|
|
|
|
2009-08-13 03:34:10 +00:00
|
|
|
SystemTimeToFileTime(&epoch, &temp);
|
2004-03-16 05:52:24 +00:00
|
|
|
|
2009-08-13 03:34:10 +00:00
|
|
|
i1.LowPart = t->absolute.dwLowDateTime;
|
|
|
|
i1.HighPart = t->absolute.dwHighDateTime;
|
|
|
|
i2.LowPart = temp.dwLowDateTime;
|
|
|
|
i2.HighPart = temp.dwHighDateTime;
|
|
|
|
|
|
|
|
i3 = (i1.QuadPart - i2.QuadPart) / 10000000;
|
|
|
|
|
2009-08-14 07:51:08 +00:00
|
|
|
return ((isc_uint32_t)i3);
|
2004-03-16 05:52:24 +00:00
|
|
|
}
|
|
|
|
|
2000-03-10 17:50:36 +00:00
|
|
|
isc_uint32_t
|
2001-10-08 18:58:11 +00:00
|
|
|
isc_time_nanoseconds(const isc_time_t *t) {
|
2009-08-13 03:34:10 +00:00
|
|
|
ULARGE_INTEGER i;
|
2000-03-10 17:50:36 +00:00
|
|
|
|
2009-08-13 03:34:10 +00:00
|
|
|
i.LowPart = t->absolute.dwLowDateTime;
|
|
|
|
i.HighPart = t->absolute.dwHighDateTime;
|
|
|
|
return ((isc_uint32_t)(i.QuadPart % 10000000) * 100);
|
2000-03-10 17:50:36 +00:00
|
|
|
}
|
2001-08-31 22:31:18 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
isc_time_formattimestamp(const isc_time_t *t, char *buf, unsigned int len) {
|
|
|
|
FILETIME localft;
|
|
|
|
SYSTEMTIME st;
|
2001-10-13 01:57:37 +00:00
|
|
|
char DateBuf[50];
|
|
|
|
char TimeBuf[50];
|
2008-08-29 23:47:22 +00:00
|
|
|
|
2001-12-19 03:46:57 +00:00
|
|
|
static const char badtime[] = "99-Bad-9999 99:99:99.999";
|
2008-08-29 23:47:22 +00:00
|
|
|
|
2001-08-31 22:31:18 +00:00
|
|
|
REQUIRE(len > 0);
|
|
|
|
if (FileTimeToLocalFileTime(&t->absolute, &localft) &&
|
2001-10-13 01:57:37 +00:00
|
|
|
FileTimeToSystemTime(&localft, &st)) {
|
2003-10-17 03:46:46 +00:00
|
|
|
GetDateFormat(LOCALE_USER_DEFAULT, 0, &st, "dd-MMM-yyyy",
|
|
|
|
DateBuf, 50);
|
2001-10-13 01:57:37 +00:00
|
|
|
GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOTIMEMARKER|
|
|
|
|
TIME_FORCE24HOURFORMAT, &st, NULL, TimeBuf, 50);
|
2008-08-29 23:47:22 +00:00
|
|
|
|
2001-10-13 01:57:37 +00:00
|
|
|
snprintf(buf, len, "%s %s.%03u", DateBuf, TimeBuf,
|
|
|
|
st.wMilliseconds);
|
2008-08-29 23:47:22 +00:00
|
|
|
|
2001-10-13 01:57:37 +00:00
|
|
|
} else
|
2001-10-08 01:20:08 +00:00
|
|
|
snprintf(buf, len, badtime);
|
2001-08-31 22:31:18 +00:00
|
|
|
}
|
2006-12-21 06:03:37 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
isc_time_formathttptimestamp(const isc_time_t *t, char *buf, unsigned int len) {
|
|
|
|
SYSTEMTIME st;
|
|
|
|
char DateBuf[50];
|
|
|
|
char TimeBuf[50];
|
2008-08-29 23:47:22 +00:00
|
|
|
|
2009-07-17 06:25:45 +00:00
|
|
|
/* strftime() format: "%a, %d %b %Y %H:%M:%S GMT" */
|
|
|
|
|
2006-12-21 06:03:37 +00:00
|
|
|
REQUIRE(len > 0);
|
|
|
|
if (FileTimeToSystemTime(&t->absolute, &st)) {
|
2009-07-17 06:25:45 +00:00
|
|
|
GetDateFormat(LOCALE_USER_DEFAULT, 0, &st,
|
|
|
|
"ddd',', dd-MMM-yyyy", DateBuf, 50);
|
2006-12-21 06:03:37 +00:00
|
|
|
GetTimeFormat(LOCALE_USER_DEFAULT,
|
|
|
|
TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT,
|
|
|
|
&st, "hh':'mm':'ss", TimeBuf, 50);
|
2008-08-29 23:47:22 +00:00
|
|
|
|
2006-12-21 06:03:37 +00:00
|
|
|
snprintf(buf, len, "%s %s GMT", DateBuf, TimeBuf);
|
|
|
|
} else {
|
|
|
|
buf[0] = 0;
|
|
|
|
}
|
|
|
|
}
|
2009-07-17 06:25:45 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
isc_time_formatISO8601(const isc_time_t *t, char *buf, unsigned int len) {
|
|
|
|
SYSTEMTIME st;
|
|
|
|
char DateBuf[50];
|
|
|
|
char TimeBuf[50];
|
|
|
|
|
|
|
|
/* strtime() format: "%Y-%m-%dT%H:%M:%SZ" */
|
|
|
|
|
|
|
|
REQUIRE(len > 0);
|
|
|
|
if (FileTimeToSystemTime(&t->absolute, &st)) {
|
|
|
|
GetDateFormat(LOCALE_NEUTRAL, 0, &st, "yyyy-MM-dd",
|
|
|
|
DateBuf, 50);
|
|
|
|
GetTimeFormat(LOCALE_NEUTRAL,
|
|
|
|
TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT,
|
|
|
|
&st, "hh':'mm':'ss", TimeBuf, 50);
|
2012-12-04 14:59:56 +11:00
|
|
|
snprintf(buf, len, "%sT%sZ", DateBuf, TimeBuf);
|
2009-07-17 06:25:45 +00:00
|
|
|
} else {
|
|
|
|
buf[0] = 0;
|
|
|
|
}
|
|
|
|
}
|