1998-12-12 20:48:14 +00:00
|
|
|
/*
|
2000-06-21 22:05:07 +00:00
|
|
|
* Copyright (C) 1998-2000 Internet Software Consortium.
|
1998-12-12 20:48:14 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
|
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
|
|
|
* CONSORTIUM 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-10-15 01:20:28 +00:00
|
|
|
|
1998-12-12 19:25:20 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
1998-10-15 01:20:28 +00:00
|
|
|
#include <errno.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 <limits.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <time.h>
|
1998-10-15 01:20:28 +00:00
|
|
|
|
2000-05-08 16:30:49 +00:00
|
|
|
#include <sys/time.h> /* Required for struct timeval on some platforms. */
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <isc/string.h>
|
1998-10-15 01:20:28 +00:00
|
|
|
#include <isc/time.h>
|
2000-04-28 01:12:23 +00:00
|
|
|
#include <isc/util.h>
|
1998-10-15 01:20:28 +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
|
|
|
#define NS_PER_S 1000000000 /* Nanoseconds per second. */
|
|
|
|
#define NS_PER_US 1000 /* Nanoseconds per microsecond. */
|
|
|
|
#define US_PER_S 1000000 /* Microseconds per second. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All of the INSIST()s checks of nanoseconds < NS_PER_S are for
|
|
|
|
* consistency checking of the type. In lieu of magic numbers, it
|
|
|
|
* is the best we've got. The check is only performed on functions which
|
|
|
|
* need an initialized type.
|
|
|
|
*/
|
|
|
|
|
1998-10-23 23:01:41 +00:00
|
|
|
/***
|
|
|
|
*** Intervals
|
|
|
|
***/
|
|
|
|
|
1999-06-12 01:15:05 +00:00
|
|
|
static isc_interval_t zero_interval = { 0, 0 };
|
|
|
|
isc_interval_t *isc_interval_zero = &zero_interval;
|
|
|
|
|
1998-10-23 23:01:41 +00:00
|
|
|
void
|
1998-12-13 23:45:21 +00:00
|
|
|
isc_interval_set(isc_interval_t *i,
|
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
|
|
|
unsigned int seconds, unsigned int nanoseconds)
|
|
|
|
{
|
1998-10-23 23:01:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set 'i' to a value representing an interval of 'seconds' seconds
|
|
|
|
* and 'nanoseconds' nanoseconds, suitable for use in isc_time_add()
|
|
|
|
* and isc_time_subtract().
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(i != NULL);
|
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
|
|
|
REQUIRE(nanoseconds < NS_PER_S);
|
1998-10-23 23:01:41 +00:00
|
|
|
|
|
|
|
i->seconds = seconds;
|
|
|
|
i->nanoseconds = nanoseconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_boolean_t
|
1998-12-13 23:45:21 +00:00
|
|
|
isc_interval_iszero(isc_interval_t *i) {
|
1998-10-23 23:01:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns ISC_TRUE iff. 'i' is the zero interval.
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(i != NULL);
|
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
|
|
|
INSIST(i->nanoseconds < NS_PER_S);
|
1998-10-23 23:01:41 +00:00
|
|
|
|
|
|
|
if (i->seconds == 0 && i->nanoseconds == 0)
|
|
|
|
return (ISC_TRUE);
|
|
|
|
|
|
|
|
return (ISC_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
*** Absolute Times
|
|
|
|
***/
|
|
|
|
|
1999-06-12 01:15:05 +00:00
|
|
|
static isc_time_t epoch = { 0, 0 };
|
|
|
|
isc_time_t *isc_time_epoch = &epoch;
|
|
|
|
|
2000-04-24 20:58:03 +00:00
|
|
|
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);
|
2000-05-18 18:59:38 +00:00
|
|
|
REQUIRE(nanoseconds < NS_PER_S);
|
2000-04-24 20:58:03 +00:00
|
|
|
|
|
|
|
t->seconds = seconds;
|
|
|
|
t->nanoseconds = nanoseconds;
|
|
|
|
}
|
|
|
|
|
1998-10-23 23:01:41 +00:00
|
|
|
void
|
1998-12-13 23:45:21 +00:00
|
|
|
isc_time_settoepoch(isc_time_t *t) {
|
1998-10-23 23:01:41 +00:00
|
|
|
/*
|
|
|
|
* Set 't' to the time of the epoch.
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(t != NULL);
|
|
|
|
|
|
|
|
t->seconds = 0;
|
|
|
|
t->nanoseconds = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_boolean_t
|
1998-12-13 23:45:21 +00:00
|
|
|
isc_time_isepoch(isc_time_t *t) {
|
1998-10-23 23:01:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns ISC_TRUE iff. 't' is the epoch ("time zero").
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(t != NULL);
|
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
|
|
|
INSIST(t->nanoseconds < NS_PER_S);
|
1998-10-23 23:01:41 +00:00
|
|
|
|
|
|
|
if (t->seconds == 0 && t->nanoseconds == 0)
|
|
|
|
return (ISC_TRUE);
|
|
|
|
|
|
|
|
return (ISC_FALSE);
|
|
|
|
}
|
|
|
|
|
1998-10-26 23:07:57 +00:00
|
|
|
isc_result_t
|
1999-06-12 01:15:05 +00:00
|
|
|
isc_time_now(isc_time_t *t) {
|
1998-10-15 01:20:28 +00:00
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
/*
|
1998-10-23 23:01:41 +00:00
|
|
|
* Set *t to the current absolute time.
|
1998-10-15 01:20:28 +00:00
|
|
|
*/
|
|
|
|
|
1998-10-23 23:01:41 +00:00
|
|
|
REQUIRE(t != NULL);
|
1998-10-15 01:20:28 +00:00
|
|
|
|
|
|
|
if (gettimeofday(&tv, NULL) == -1) {
|
1998-10-21 01:13:50 +00:00
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__, strerror(errno));
|
1998-10-15 01:20:28 +00:00
|
|
|
return (ISC_R_UNEXPECTED);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/*
|
|
|
|
* Does POSIX guarantee the signedness of tv_sec and tv_usec? If not,
|
|
|
|
* then this test will generate warnings for platforms on which it is
|
|
|
|
* unsigned. In any event, the chances of any of these problems
|
|
|
|
* happening are pretty much zero, but since the libisc library ensures
|
|
|
|
* certain things to be true ...
|
|
|
|
*/
|
|
|
|
if (tv.tv_sec < 0 || tv.tv_usec < 0 || tv.tv_usec >= US_PER_S)
|
|
|
|
return (ISC_R_UNEXPECTED);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ensure the tv_sec value fits in t->seconds.
|
|
|
|
*/
|
|
|
|
if (sizeof(tv.tv_sec) > sizeof(t->seconds) &&
|
|
|
|
((tv.tv_sec | (unsigned int)-1) ^ (unsigned int)-1) != 0)
|
|
|
|
return (ISC_R_RANGE);
|
|
|
|
|
1998-10-23 23:01:41 +00:00
|
|
|
t->seconds = tv.tv_sec;
|
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
|
|
|
t->nanoseconds = tv.tv_usec * NS_PER_US;
|
1998-10-15 01:20:28 +00:00
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
1999-06-12 01:15:05 +00:00
|
|
|
isc_result_t
|
|
|
|
isc_time_nowplusinterval(isc_time_t *t, isc_interval_t *i) {
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set *t to the current absolute time + i.
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(t != NULL);
|
|
|
|
REQUIRE(i != NULL);
|
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
|
|
|
INSIST(i->nanoseconds < NS_PER_S);
|
|
|
|
|
1999-06-12 01:15:05 +00:00
|
|
|
if (gettimeofday(&tv, NULL) == -1) {
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__, strerror(errno));
|
|
|
|
return (ISC_R_UNEXPECTED);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/*
|
|
|
|
* Does POSIX guarantee the signedness of tv_sec and tv_usec? If not,
|
|
|
|
* then this test will generate warnings for platforms on which it is
|
|
|
|
* unsigned. In any event, the chances of any of these problems
|
|
|
|
* happening are pretty much zero, but since the libisc library ensures
|
|
|
|
* certain things to be true ...
|
|
|
|
*/
|
|
|
|
if (tv.tv_sec < 0 || tv.tv_usec < 0 || tv.tv_usec >= US_PER_S)
|
|
|
|
return (ISC_R_UNEXPECTED);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ensure the resulting seconds value fits in the size of an
|
|
|
|
* unsigned int. (It is written this way as a slight optimization;
|
|
|
|
* note that even if both values == INT_MAX, then when added
|
|
|
|
* and getting another 1 added below the result is UINT_MAX.)
|
|
|
|
*/
|
|
|
|
if ((tv.tv_sec > INT_MAX || i->seconds > INT_MAX) &&
|
|
|
|
((long long)tv.tv_sec + i->seconds > UINT_MAX))
|
|
|
|
return (ISC_R_RANGE);
|
|
|
|
|
1999-06-12 01:15:05 +00:00
|
|
|
t->seconds = tv.tv_sec + i->seconds;
|
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
|
|
|
t->nanoseconds = tv.tv_usec * NS_PER_US + i->nanoseconds;
|
|
|
|
if (t->nanoseconds > NS_PER_S) {
|
1999-06-12 01:15:05 +00:00
|
|
|
t->seconds++;
|
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
|
|
|
t->nanoseconds -= NS_PER_S;
|
1999-06-12 01:15:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
1998-10-15 01:20:28 +00:00
|
|
|
int
|
1998-12-13 23:45:21 +00:00
|
|
|
isc_time_compare(isc_time_t *t1, isc_time_t *t2) {
|
1998-10-23 23:01:41 +00:00
|
|
|
|
1998-10-15 01:20:28 +00:00
|
|
|
/*
|
1998-10-22 01:33:20 +00:00
|
|
|
* Compare the times referenced by 't1' and 't2'
|
1998-10-15 01:20:28 +00:00
|
|
|
*/
|
|
|
|
|
1998-10-22 01:33:20 +00:00
|
|
|
REQUIRE(t1 != NULL && t2 != NULL);
|
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
|
|
|
INSIST(t1->nanoseconds < NS_PER_S && t2->nanoseconds < NS_PER_S);
|
1998-10-15 01:20:28 +00:00
|
|
|
|
1998-10-22 01:33:20 +00:00
|
|
|
if (t1->seconds < t2->seconds)
|
1998-10-15 01:20:28 +00:00
|
|
|
return (-1);
|
1998-10-22 01:33:20 +00:00
|
|
|
if (t1->seconds > t2->seconds)
|
1998-10-15 01:20:28 +00:00
|
|
|
return (1);
|
1998-10-22 01:33:20 +00:00
|
|
|
if (t1->nanoseconds < t2->nanoseconds)
|
1998-10-15 01:20:28 +00:00
|
|
|
return (-1);
|
1998-10-22 01:33:20 +00:00
|
|
|
if (t1->nanoseconds > t2->nanoseconds)
|
1998-10-15 01:20:28 +00:00
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
isc_time_add(isc_time_t *t, isc_interval_t *i, isc_time_t *result) {
|
1998-10-15 01:20:28 +00:00
|
|
|
/*
|
1998-10-23 23:01:41 +00:00
|
|
|
* Add 't' to 'i', storing the result in 'result'.
|
1998-10-15 01:20:28 +00:00
|
|
|
*/
|
|
|
|
|
1998-10-23 23:01:41 +00:00
|
|
|
REQUIRE(t != NULL && i != NULL && result != NULL);
|
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
|
|
|
INSIST(t->nanoseconds < NS_PER_S && i->nanoseconds < NS_PER_S);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ensure the resulting seconds value fits in the size of an
|
|
|
|
* unsigned int. (It is written this way as a slight optimization;
|
|
|
|
* note that even if both values == INT_MAX, then when added
|
|
|
|
* and getting another 1 added below the result is UINT_MAX.)
|
|
|
|
*/
|
|
|
|
if ((t->seconds > INT_MAX || i->seconds > INT_MAX) &&
|
|
|
|
((long long)t->seconds + i->seconds > UINT_MAX))
|
|
|
|
return (ISC_R_RANGE);
|
1998-10-15 01:20:28 +00:00
|
|
|
|
1998-10-23 23:01:41 +00:00
|
|
|
result->seconds = t->seconds + i->seconds;
|
|
|
|
result->nanoseconds = t->nanoseconds + i->nanoseconds;
|
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
|
|
|
if (result->nanoseconds > NS_PER_S) {
|
1998-10-23 23:01:41 +00:00
|
|
|
result->seconds++;
|
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
|
|
|
result->nanoseconds -= NS_PER_S;
|
1998-10-15 01:20:28 +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
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
1998-10-15 01:20:28 +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
|
1998-12-13 23:45:21 +00:00
|
|
|
isc_time_subtract(isc_time_t *t, isc_interval_t *i, isc_time_t *result) {
|
1998-10-15 01:20:28 +00:00
|
|
|
/*
|
1998-10-23 23:01:41 +00:00
|
|
|
* Subtract 'i' from 't', storing the result in 'result'.
|
1998-10-15 01:20:28 +00:00
|
|
|
*/
|
|
|
|
|
1998-10-23 23:01:41 +00:00
|
|
|
REQUIRE(t != NULL && i != NULL && result != NULL);
|
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
|
|
|
INSIST(t->nanoseconds < NS_PER_S && i->nanoseconds < NS_PER_S);
|
|
|
|
|
|
|
|
if ((unsigned int)t->seconds < i->seconds ||
|
|
|
|
((unsigned int)t->seconds == i->seconds &&
|
|
|
|
t->nanoseconds < i->nanoseconds))
|
|
|
|
return (ISC_R_RANGE);
|
|
|
|
|
1998-10-23 23:01:41 +00:00
|
|
|
result->seconds = t->seconds - i->seconds;
|
|
|
|
if (t->nanoseconds >= i->nanoseconds)
|
|
|
|
result->nanoseconds = t->nanoseconds - i->nanoseconds;
|
1998-10-15 01:20:28 +00:00
|
|
|
else {
|
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
|
|
|
result->nanoseconds = NS_PER_S - i->nanoseconds +
|
1998-10-23 23:01:41 +00:00
|
|
|
t->nanoseconds;
|
|
|
|
result->seconds--;
|
1998-10-15 01:20:28 +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
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
1998-10-15 01:20:28 +00:00
|
|
|
}
|
1999-10-09 02:40:32 +00:00
|
|
|
|
|
|
|
isc_uint64_t
|
|
|
|
isc_time_microdiff(isc_time_t *t1, isc_time_t *t2) {
|
|
|
|
isc_uint64_t i1, i2, i3;
|
|
|
|
|
|
|
|
REQUIRE(t1 != NULL && t2 != NULL);
|
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
|
|
|
INSIST(t1->nanoseconds < NS_PER_S && t2->nanoseconds < NS_PER_S);
|
1999-10-09 02:40:32 +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
|
|
|
i1 = (isc_uint64_t)t1->seconds * NS_PER_S + t1->nanoseconds;
|
|
|
|
i2 = (isc_uint64_t)t2->seconds * NS_PER_S + t2->nanoseconds;
|
1999-10-09 02:40:32 +00:00
|
|
|
|
|
|
|
if (i1 <= i2)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
i3 = i1 - i2;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert to microseconds.
|
|
|
|
*/
|
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
|
|
|
i3 = (i1 - i2) / NS_PER_US;
|
1999-10-09 02:40:32 +00:00
|
|
|
|
|
|
|
return (i3);
|
|
|
|
}
|
2000-03-10 17:49:27 +00:00
|
|
|
|
|
|
|
isc_uint32_t
|
|
|
|
isc_time_seconds(isc_time_t *t) {
|
2000-04-24 20:58:03 +00:00
|
|
|
REQUIRE(t != NULL);
|
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
|
|
|
INSIST(t->nanoseconds < NS_PER_S);
|
2000-04-24 20:58:03 +00:00
|
|
|
|
2000-03-10 17:49:27 +00:00
|
|
|
return ((isc_uint32_t)t->seconds);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
isc_time_secondsastimet(isc_time_t *t, time_t *secondsp) {
|
|
|
|
isc_uint64_t i;
|
|
|
|
time_t seconds;
|
|
|
|
|
|
|
|
REQUIRE(t != NULL);
|
|
|
|
INSIST(t->nanoseconds < NS_PER_S);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ensure that the number of seconds represented by t->seconds
|
|
|
|
* can be represented by a time_t. Since t->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.)
|
|
|
|
*
|
|
|
|
* The mission, then, is to avoid generating any kind of warning
|
|
|
|
* about "signed versus unsigned" while trying to determine if the
|
|
|
|
* the unsigned int t->seconds is out range for tv_sec, which is
|
|
|
|
* pretty much only true if time_t is a signed integer of the same
|
|
|
|
* size as the return value of isc_time_seconds.
|
|
|
|
*
|
2000-05-24 21:36:01 +00:00
|
|
|
* The use of the 64 bit integer ``i'' takes advantage of C's
|
|
|
|
* conversion rules to either zero fill or sign extend the widened
|
|
|
|
* type.
|
|
|
|
*
|
|
|
|
* Solaris 5.6 gives this warning about the left shift:
|
|
|
|
* warning: integer overflow detected: op "<<"
|
|
|
|
* if the U(nsigned) qualifier is not on the 1.
|
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
|
|
|
*/
|
|
|
|
seconds = (time_t)t->seconds;
|
|
|
|
|
|
|
|
INSIST(sizeof(unsigned int) == sizeof(isc_uint32_t));
|
|
|
|
INSIST(sizeof(time_t) >= sizeof(isc_uint32_t));
|
|
|
|
|
|
|
|
if (sizeof(time_t) == sizeof(isc_uint32_t) && /* Same size. */
|
|
|
|
(time_t)0.5 != 0.5 && /* Not a floating point type. */
|
|
|
|
(i = (time_t)-1) != 4294967295u && /* Is signed. */
|
2000-05-24 21:36:01 +00:00
|
|
|
(seconds &
|
|
|
|
(1U << (sizeof(time_t) * CHAR_BIT - 1))) != 0) { /* Negative. */
|
2000-05-24 02:39:01 +00:00
|
|
|
/*
|
2000-05-24 21:36:01 +00:00
|
|
|
* This UNUSED() is here to shut up the IRIX compiler:
|
2000-05-24 02:39:01 +00:00
|
|
|
* variable "i" was set but never used
|
|
|
|
* when the value of i *was* used in the third test.
|
|
|
|
* (Let's hope the compiler got the actual test right.)
|
|
|
|
*/
|
|
|
|
UNUSED(i);
|
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-05-24 02:39:01 +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
|
|
|
|
|
|
|
*secondsp = seconds;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2000-03-10 17:49:27 +00:00
|
|
|
isc_uint32_t
|
|
|
|
isc_time_nanoseconds(isc_time_t *t) {
|
2000-04-24 20:58:03 +00:00
|
|
|
REQUIRE(t != NULL);
|
|
|
|
|
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
|
|
|
ENSURE(t->nanoseconds < NS_PER_S);
|
2000-03-10 17:49:27 +00:00
|
|
|
|
|
|
|
return ((isc_uint32_t)t->nanoseconds);
|
|
|
|
}
|