mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-01 06:55:30 +00:00
The epoch is once again zero in Win32;
removed win32 implementations of isc_time_set(), isc_time_seconds() and isc_time_secondsastimet() as they are no longer needed
This commit is contained in:
@@ -15,13 +15,12 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: DLLMain.c,v 1.3 2001/07/17 19:16:55 gson Exp $ */
|
/* $Id: DLLMain.c,v 1.4 2001/09/01 00:55:25 gson Exp $ */
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
BOOL InitSockets(void);
|
BOOL InitSockets(void);
|
||||||
void isc_time_initepoch();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called when we enter the DLL
|
* Called when we enter the DLL
|
||||||
@@ -38,7 +37,6 @@ __declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE hinstDLL,
|
|||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH:
|
||||||
if (!InitSockets())
|
if (!InitSockets())
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
isc_time_initepoch();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* The attached process creates a new thread. */
|
/* The attached process creates a new thread. */
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: time.h,v 1.21 2001/09/01 00:18:43 gson Exp $ */
|
/* $Id: time.h,v 1.22 2001/09/01 00:55:27 gson Exp $ */
|
||||||
|
|
||||||
#ifndef ISC_TIME_H
|
#ifndef ISC_TIME_H
|
||||||
#define ISC_TIME_H 1
|
#define ISC_TIME_H 1
|
||||||
@@ -84,23 +84,6 @@ struct isc_time {
|
|||||||
|
|
||||||
extern isc_time_t *isc_time_epoch;
|
extern isc_time_t *isc_time_epoch;
|
||||||
|
|
||||||
void
|
|
||||||
isc_time_set(isc_time_t *t, unsigned int seconds, unsigned int nanoseconds);
|
|
||||||
/*
|
|
||||||
* Set 't' to a particular number of seconds + nanoseconds since the epoch.
|
|
||||||
*
|
|
||||||
* Notes:
|
|
||||||
* This call is equivalent to:
|
|
||||||
*
|
|
||||||
* isc_time_settoepoch(t);
|
|
||||||
* isc_interval_set(i, seconds, nanoseconds);
|
|
||||||
* isc_time_add(t, i, t);
|
|
||||||
*
|
|
||||||
* Requires:
|
|
||||||
* 't' is a valid pointer.
|
|
||||||
* nanoseconds < 1000000000.
|
|
||||||
*/
|
|
||||||
|
|
||||||
void
|
void
|
||||||
isc_time_settoepoch(isc_time_t *t);
|
isc_time_settoepoch(isc_time_t *t);
|
||||||
/*
|
/*
|
||||||
@@ -229,39 +212,6 @@ isc_time_microdiff(isc_time_t *t1, isc_time_t *t2);
|
|||||||
* The difference of t1 - t2, or 0 if t1 <= t2.
|
* The difference of t1 - t2, or 0 if t1 <= t2.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
isc_uint32_t
|
|
||||||
isc_time_seconds(isc_time_t *t);
|
|
||||||
/*
|
|
||||||
* Return the number of seconds since the epoch stored in a time structure.
|
|
||||||
*
|
|
||||||
* Requires:
|
|
||||||
*
|
|
||||||
* 't' is a valid pointer.
|
|
||||||
*/
|
|
||||||
|
|
||||||
isc_result_t
|
|
||||||
isc_time_secondsastimet(isc_time_t *t, time_t *secondsp);
|
|
||||||
/*
|
|
||||||
* Ensure the number of seconds in an isc_time_t is representable by a time_t.
|
|
||||||
*
|
|
||||||
* Notes:
|
|
||||||
* The number of seconds stored in an isc_time_t might be larger
|
|
||||||
* than the number of seconds a time_t is able to handle. Since
|
|
||||||
* time_t is mostly opaque according to the ANSI/ISO standard
|
|
||||||
* (essentially, all you can be sure of is that it is an arithmetic type,
|
|
||||||
* not even necessarily integral), it can be tricky to ensure that
|
|
||||||
* the isc_time_t is in the range a time_t can handle. Use this
|
|
||||||
* function in place of isc_time_seconds() any time you need to set a
|
|
||||||
* time_t from an isc_time_t.
|
|
||||||
*
|
|
||||||
* Requires:
|
|
||||||
* 't' is a valid pointer.
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* Success
|
|
||||||
* Out of range
|
|
||||||
*/
|
|
||||||
|
|
||||||
isc_uint32_t
|
isc_uint32_t
|
||||||
isc_time_nanoseconds(isc_time_t *t);
|
isc_time_nanoseconds(isc_time_t *t);
|
||||||
/*
|
/*
|
||||||
|
@@ -15,18 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: time.c,v 1.26 2001/08/31 22:31:17 gson Exp $ */
|
/* $Id: time.c,v 1.27 2001/09/01 00:55:24 gson Exp $ */
|
||||||
|
|
||||||
/*
|
|
||||||
* Windows has a different epoch than Unix. Therefore this code sets the epoch
|
|
||||||
* value to the Unix epoch. Care should be used when using these routines to
|
|
||||||
* ensure that this difference is taken into account. System and File times
|
|
||||||
* may require adjusting for this when modifying any time value that needs
|
|
||||||
* to be an absolute Windows time.
|
|
||||||
*
|
|
||||||
* Currently only epoch-specific code and the isc_time_seconds
|
|
||||||
* and isc_time_secondsastimet use the epoch-adjusted code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
@@ -58,18 +47,9 @@
|
|||||||
*** Absolute Times
|
*** Absolute Times
|
||||||
***/
|
***/
|
||||||
|
|
||||||
static isc_time_t epoch = { 0, 0 };
|
static isc_time_t epoch = { { 0, 0 } };
|
||||||
isc_time_t *isc_time_epoch = &epoch;
|
isc_time_t *isc_time_epoch = &epoch;
|
||||||
|
|
||||||
void
|
|
||||||
TimetToFileTime(time_t t, LPFILETIME pft) {
|
|
||||||
LONGLONG i;
|
|
||||||
|
|
||||||
i = Int32x32To64(t, 10000000) + 116444736000000000;
|
|
||||||
pft->dwLowDateTime = (DWORD) i;
|
|
||||||
pft->dwHighDateTime = (DWORD) (i >>32);
|
|
||||||
}
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
*** Intervals
|
*** Intervals
|
||||||
***/
|
***/
|
||||||
@@ -97,43 +77,20 @@ isc_interval_iszero(isc_interval_t *i) {
|
|||||||
return (ISC_FALSE);
|
return (ISC_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
isc_time_set(isc_time_t *t, unsigned int seconds, unsigned int nanoseconds) {
|
|
||||||
ULARGE_INTEGER i;
|
|
||||||
|
|
||||||
REQUIRE(t != NULL);
|
|
||||||
REQUIRE(nanoseconds < NS_PER_S);
|
|
||||||
|
|
||||||
i.QuadPart = (LONGLONG)seconds * INTERVALS_PER_S
|
|
||||||
+ nanoseconds / NS_INTERVAL;
|
|
||||||
|
|
||||||
t->absolute.dwLowDateTime = i.LowPart
|
|
||||||
+ epoch.absolute.dwLowDateTime;
|
|
||||||
t->absolute.dwHighDateTime = i.HighPart
|
|
||||||
+ epoch.absolute.dwHighDateTime;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
isc_time_initepoch() {
|
|
||||||
TimetToFileTime(0, &epoch.absolute);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
isc_time_settoepoch(isc_time_t *t) {
|
isc_time_settoepoch(isc_time_t *t) {
|
||||||
REQUIRE(t != NULL);
|
REQUIRE(t != NULL);
|
||||||
|
|
||||||
t->absolute.dwLowDateTime = epoch.absolute.dwLowDateTime;
|
t->absolute.dwLowDateTime = 0;
|
||||||
t->absolute.dwHighDateTime = epoch.absolute.dwHighDateTime;
|
t->absolute.dwHighDateTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
isc_boolean_t
|
isc_boolean_t
|
||||||
isc_time_isepoch(isc_time_t *t) {
|
isc_time_isepoch(isc_time_t *t) {
|
||||||
REQUIRE(t != NULL);
|
REQUIRE(t != NULL);
|
||||||
|
|
||||||
if (t->absolute.dwLowDateTime == epoch.absolute.dwLowDateTime &&
|
if (t->absolute.dwLowDateTime == 0 &&
|
||||||
t->absolute.dwHighDateTime == epoch.absolute.dwHighDateTime)
|
t->absolute.dwHighDateTime == 0)
|
||||||
return (ISC_TRUE);
|
return (ISC_TRUE);
|
||||||
|
|
||||||
return (ISC_FALSE);
|
return (ISC_FALSE);
|
||||||
@@ -141,7 +98,6 @@ isc_time_isepoch(isc_time_t *t) {
|
|||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
isc_time_now(isc_time_t *t) {
|
isc_time_now(isc_time_t *t) {
|
||||||
|
|
||||||
REQUIRE(t != NULL);
|
REQUIRE(t != NULL);
|
||||||
|
|
||||||
GetSystemTimeAsFileTime(&t->absolute);
|
GetSystemTimeAsFileTime(&t->absolute);
|
||||||
@@ -242,126 +198,6 @@ isc_time_microdiff(isc_time_t *t1, isc_time_t *t2) {
|
|||||||
return (i3);
|
return (i3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Note that the value returned is the seconds relative to the Unix
|
|
||||||
* epoch rather than the seconds since Windows epoch. This is for
|
|
||||||
* compatibility with the Unix side.
|
|
||||||
*/
|
|
||||||
isc_uint32_t
|
|
||||||
isc_time_seconds(isc_time_t *t) {
|
|
||||||
ULARGE_INTEGER i;
|
|
||||||
|
|
||||||
REQUIRE(t != NULL);
|
|
||||||
|
|
||||||
i.LowPart = t->absolute.dwLowDateTime -
|
|
||||||
epoch.absolute.dwLowDateTime;
|
|
||||||
i.HighPart = t->absolute.dwHighDateTime -
|
|
||||||
epoch.absolute.dwHighDateTime;
|
|
||||||
|
|
||||||
return ((isc_uint32_t)(i.QuadPart / INTERVALS_PER_S));
|
|
||||||
}
|
|
||||||
|
|
||||||
isc_result_t
|
|
||||||
isc_time_secondsastimet(isc_time_t *t, time_t *secondsp) {
|
|
||||||
ULARGE_INTEGER i1, i2;
|
|
||||||
time_t seconds;
|
|
||||||
|
|
||||||
REQUIRE(t != NULL);
|
|
||||||
|
|
||||||
i1.LowPart = t->absolute.dwLowDateTime;
|
|
||||||
i1.HighPart = t->absolute.dwHighDateTime;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the time_t zero equivalent in FILETIME
|
|
||||||
* The zero point for FILETIME is 1 January, 1601
|
|
||||||
* while for timet it is 1 January, 1970
|
|
||||||
*/
|
|
||||||
i1.LowPart -= epoch.absolute.dwLowDateTime;
|
|
||||||
i1.HighPart -= epoch.absolute.dwHighDateTime;
|
|
||||||
|
|
||||||
i1.QuadPart /= INTERVALS_PER_S;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Ensure that the number of seconds can be represented by a time_t.
|
|
||||||
* Since the number seconds is an unsigned int and since time_t is
|
|
||||||
* mostly opaque, this is trickier than it seems. (This standardized
|
|
||||||
* opaqueness of time_t is *very* * frustrating; time_t is not even
|
|
||||||
* limited to being an integral type.) Thought it is known at the
|
|
||||||
* time of this writing that time_t is a signed long on the Win32
|
|
||||||
* platform, the full treatment is given to figuring out if things
|
|
||||||
* fit to allow for future Windows platforms where time_t is *not*
|
|
||||||
* a signed long, or where perhaps a signed long is longer than
|
|
||||||
* it currently is.
|
|
||||||
*/
|
|
||||||
seconds = (time_t)i1.QuadPart;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* First, only do the range tests if the type of size_t is integral.
|
|
||||||
* Float/double easily include the maximum possible values.
|
|
||||||
*/
|
|
||||||
if ((time_t)0.5 != 0.5) {
|
|
||||||
/*
|
|
||||||
* Did all the bits make it in?
|
|
||||||
*/
|
|
||||||
if ((seconds & i1.QuadPart) != i1.QuadPart)
|
|
||||||
return (ISC_R_RANGE);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Is time_t signed with the high bit set?
|
|
||||||
*
|
|
||||||
* The first test (the sizeof comparison) determines
|
|
||||||
* whether we can even deduce the signedness of time_t
|
|
||||||
* by using ANSI's rule about integer conversion to
|
|
||||||
* wider integers.
|
|
||||||
*
|
|
||||||
* The second test uses that ANSI rule to see whether
|
|
||||||
* the value of time_t was sign extended into QuadPart.
|
|
||||||
* If the test is true, then time_t is signed.
|
|
||||||
*
|
|
||||||
* The final test ensures the high bit is not set, or
|
|
||||||
* the value is negative and hence there is a range error.
|
|
||||||
*/
|
|
||||||
if (sizeof(time_t) < sizeof(i2.QuadPart) &&
|
|
||||||
((i2.QuadPart = (time_t)-1) ^ (time_t)-1) != 0 &&
|
|
||||||
(seconds & (1 << (sizeof(time_t) * 8 - 1))) != 0)
|
|
||||||
return (ISC_R_RANGE);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Last test ... the size of time_t is >= that of i2.QuadPart,
|
|
||||||
* so we can't determine its signedness. Unconditionally
|
|
||||||
* declare anything with the high bit set as out of range.
|
|
||||||
* Since even the maxed signed value is ludicrously far from
|
|
||||||
* when this is being written, this rule shall not impact
|
|
||||||
* anything for all intents and purposes.
|
|
||||||
*
|
|
||||||
* How far? Well ... if FILETIME is in 100 ns intervals since
|
|
||||||
* 1600, and a QuadPart can store 9223372036854775808 such
|
|
||||||
* intervals when interpreted as signed (ie, if sizeof(time_t)
|
|
||||||
* == sizeof(QuadPart) but time_t is signed), that means
|
|
||||||
* 9223372036854775808 / INTERVALS_PER_S = 922,337,203,685
|
|
||||||
* seconds. That number divided by 60 * 60 * 24 * 365 seconds
|
|
||||||
* per year means a signed time_t can store at least 29,247
|
|
||||||
* years, with only 400 of those years used up since 1600 as I
|
|
||||||
* write this in May, 2000.
|
|
||||||
*
|
|
||||||
* (Real date calculations are of course incredibly more
|
|
||||||
* complex; I'm only describing the approximate scale of
|
|
||||||
* the numbers involved here.)
|
|
||||||
*
|
|
||||||
* If the Galactic Federation is still running libisc's time
|
|
||||||
* libray on a Windows platform in the year 27647 A.D., then
|
|
||||||
* feel free to hunt down my greatgreatgreatgreatgreat(etc)
|
|
||||||
* grandchildren and whine at them about what I did.
|
|
||||||
*/
|
|
||||||
if ((seconds & (1 << (sizeof(time_t) * 8 - 1))) != 0)
|
|
||||||
return (ISC_R_RANGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
*secondsp = seconds;
|
|
||||||
|
|
||||||
return (ISC_R_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
isc_uint32_t
|
isc_uint32_t
|
||||||
isc_time_nanoseconds(isc_time_t *t) {
|
isc_time_nanoseconds(isc_time_t *t) {
|
||||||
SYSTEMTIME st;
|
SYSTEMTIME st;
|
||||||
|
Reference in New Issue
Block a user