From 585529aaeb95a71cd3d95df2602a4688fc7c3292 Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Mon, 24 Apr 2000 20:58:03 +0000 Subject: [PATCH] 71. [cleanup] Made explicit the implicit REQUIREs of isc_time_seconds, isc_time_nanoseconds, and isc_time_subtract. 70. [func] isc_time_set() added. --- CHANGES | 11 +++++++--- lib/isc/unix/time.c | 19 ++++++++++++++++++ lib/isc/win32/time.c | 48 +++++++++++++++++++++++++++++++++----------- 3 files changed, 63 insertions(+), 15 deletions(-) diff --git a/CHANGES b/CHANGES index bae3c47c1a..09f7d38013 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ + 71. [cleanup] Made explicit the implicit REQUIREs of + isc_time_seconds, isc_time_nanoseconds, and + isc_time_subtract. + + 70. [func] isc_time_set() added. 69. [bug] The zone object's master and also-notify lists grew longer with each server reload. @@ -17,11 +22,11 @@ caller find the most-enclosing superdomain of a name. - 63 [func] generate NOTIFY messages. + 63 [func] Generate NOTIFY messages. - 62. [func] add UDP refresh support. + 62. [func] Add UDP refresh support. - 61. [cleanup] use single quotes consistently in log messages. + 61. [cleanup] Use single quotes consistently in log messages. 60. [func] Catch and disallow singleton types on message parse. diff --git a/lib/isc/unix/time.c b/lib/isc/unix/time.c index 17d3cacf4d..7751e9fd88 100644 --- a/lib/isc/unix/time.c +++ b/lib/isc/unix/time.c @@ -77,6 +77,18 @@ isc_interval_iszero(isc_interval_t *i) { static isc_time_t epoch = { 0, 0 }; isc_time_t *isc_time_epoch = &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. + */ + REQUIRE(t != NULL); + + t->seconds = seconds; + t->nanoseconds = nanoseconds; +} + void isc_time_settoepoch(isc_time_t *t) { /* @@ -195,6 +207,9 @@ isc_time_subtract(isc_time_t *t, isc_interval_t *i, isc_time_t *result) { */ REQUIRE(t != NULL && i != NULL && result != NULL); + REQUIRE((unsigned int)t->seconds > i->seconds || + ((unsigned int)t->seconds == i->seconds && + t->nanoseconds >= i->nanoseconds)); result->seconds = t->seconds - i->seconds; if (t->nanoseconds >= i->nanoseconds) @@ -230,11 +245,15 @@ isc_time_microdiff(isc_time_t *t1, isc_time_t *t2) { isc_uint32_t isc_time_seconds(isc_time_t *t) { + REQUIRE(t != NULL); + return ((isc_uint32_t)t->seconds); } isc_uint32_t isc_time_nanoseconds(isc_time_t *t) { + REQUIRE(t != NULL); + ENSURE(t->nanoseconds < 1000000000); return ((isc_uint32_t)t->nanoseconds); diff --git a/lib/isc/win32/time.c b/lib/isc/win32/time.c index 20cae49536..3a15cbaabc 100644 --- a/lib/isc/win32/time.c +++ b/lib/isc/win32/time.c @@ -84,6 +84,25 @@ isc_interval_iszero(isc_interval_t *i) { static isc_time_t epoch = { 0, 0 }; isc_time_t *isc_time_epoch = &epoch; +void +isc_time_set(isc_time_t *t, unsigned int seconds, unsigned int nanoseconds) { + ULARGE_INTEGER i; + + /* + * Set 't' to a particular number of seconds + nanoseconds since the + * epoch. + */ + REQUIRE(t != NULL); + REQUIRE(nanoseconds < 1000000000); + + i.QuadPart = (LONGLONG)seconds * INTERVALS_PER_S + + nanoseconds / NS_INTERVAL; + + t->absolute.dwLowDateTime = i.LowPart; + t->absolute.dwHighDateTime = i.HighPart; + +} + void isc_time_settoepoch(isc_time_t *t) { /* @@ -160,9 +179,8 @@ isc_time_compare(isc_time_t *t1, isc_time_t *t2) { } void -isc_time_add(isc_time_t *t, isc_interval_t *i, isc_time_t *result) -{ - ULARGE_INTEGER i1, i2; +isc_time_add(isc_time_t *t, isc_interval_t *i, isc_time_t *result) { + ULARGE_INTEGER i1; /* * Add 't' to 'i', storing the result in 'result'. @@ -173,15 +191,15 @@ isc_time_add(isc_time_t *t, isc_interval_t *i, isc_time_t *result) i1.LowPart = t->absolute.dwLowDateTime; i1.HighPart = t->absolute.dwHighDateTime; - i2.QuadPart = i1.QuadPart + i->interval; - - result->absolute.dwLowDateTime = i2.LowPart; - result->absolute.dwHighDateTime = i2.HighPart; + i1.QuadPart += i->interval; + + result->absolute.dwLowDateTime = i1.LowPart; + result->absolute.dwHighDateTime = i1.HighPart; } void isc_time_subtract(isc_time_t *t, isc_interval_t *i, isc_time_t *result) { - ULARGE_INTEGER i1, i2; + ULARGE_INTEGER i1; /* * Subtract 'i' from 't', storing the result in 'result'. @@ -192,10 +210,12 @@ isc_time_subtract(isc_time_t *t, isc_interval_t *i, isc_time_t *result) { i1.LowPart = t->absolute.dwLowDateTime; i1.HighPart = t->absolute.dwHighDateTime; - i2.QuadPart = i1.QuadPart - i->interval; - - result->absolute.dwLowDateTime = i2.LowPart; - result->absolute.dwHighDateTime = i2.HighPart; + REQUIRE(i1.QuadPart >= i->interval); + + i1.QuadPart -= i->interval; + + result->absolute.dwLowDateTime = i1.LowPart; + result->absolute.dwHighDateTime = i1.HighPart; } isc_uint64_t @@ -225,6 +245,8 @@ isc_uint32_t isc_time_seconds(isc_time_t *t) { ULARGE_INTEGER i; + REQUIRE(t != NULL); + i.LowPart = t->absolute.dwLowDateTime; i.HighPart = t->absolute.dwHighDateTime; @@ -237,6 +259,8 @@ isc_uint32_t isc_time_nanoseconds(isc_time_t *t) { ULARGE_INTEGER i; + REQUIRE(t != NULL); + i.LowPart = t->absolute.dwLowDateTime; i.HighPart = t->absolute.dwHighDateTime;