now = isc_time_now();
if (isc_time_seconds(&start) == isc_time_seconds(&now))
{
- int us = US_PER_SEC -
- (isc_time_nanoseconds(&now) /
- NS_PER_US);
+ unsigned int us = US_PER_SEC -
+ (isc_time_nanoseconds(&now) /
+ NS_PER_US);
if (us > US_PER_MS) {
usleep(us - US_PER_MS);
}
/*! \file */
+#include <inttypes.h>
#include <time.h>
#include <isc/lang.h>
#include <isc/types.h>
-enum {
- MS_PER_SEC = 1000, /*%< Milliseonds per second. */
- US_PER_MS = 1000, /*%< Microseconds per millisecond. */
- US_PER_SEC = 1000 * 1000, /*%< Microseconds per second. */
- NS_PER_US = 1000, /*%< Nanoseconds per microsecond. */
- NS_PER_MS = 1000 * 1000, /*%< Nanoseconds per millisecond. */
- NS_PER_SEC = 1000 * 1000 * 1000, /*%< Nanoseconds per second. */
-};
+/*
+ * Define various time conversion constants.
+ */
+static const unsigned int MS_PER_SEC = 1000;
+static const unsigned int US_PER_MS = 1000;
+static const unsigned int NS_PER_US = 1000;
+static const unsigned int US_PER_SEC = 1000 * 1000;
+static const unsigned int NS_PER_MS = 1000 * 1000;
+static const unsigned int NS_PER_SEC = 1000 * 1000 * 1000;
/*
* ISC_FORMATHTTPTIMESTAMP_SIZE needs to be 30 in C locale and potentially
if (clock_gettime(CLOCKSOURCE, &ts) == -1) {
FATAL_SYSERROR(errno, "clock_gettime()");
}
- INSIST(ts.tv_sec > 0 && ts.tv_nsec >= 0 && ts.tv_nsec < NS_PER_SEC);
+ INSIST(ts.tv_sec > 0 && ts.tv_nsec >= 0 &&
+ ts.tv_nsec < (long)NS_PER_SEC);
return ((isc_stdtime_t)ts.tv_sec);
}
struct timespec ts;
RUNTIME_CHECK(clock_gettime(clock, &ts) == 0);
- INSIST(ts.tv_sec >= 0 && ts.tv_nsec >= 0 && ts.tv_nsec < NS_PER_SEC);
+ INSIST(ts.tv_sec >= 0 && ts.tv_nsec >= 0 &&
+ ts.tv_nsec < (long)NS_PER_SEC);
/*
* Ensure the tv_sec value fits in t->seconds.
return (ISC_R_UNEXPECTED);
}
- if (ts.tv_sec < 0 || ts.tv_nsec < 0 || ts.tv_nsec >= NS_PER_SEC) {
+ if (ts.tv_sec < 0 || ts.tv_nsec < 0 || ts.tv_nsec >= (long)NS_PER_SEC) {
return (ISC_R_UNEXPECTED);
}
dns_test_nap(uint32_t usec) {
struct timespec ts;
- ts.tv_sec = usec / 1000000;
- ts.tv_nsec = (usec % 1000000) * 1000;
+ ts.tv_sec = usec / (long)US_PER_SEC;
+ ts.tv_nsec = (usec % (long)US_PER_SEC) * (long)NS_PER_US;
nanosleep(&ts, NULL);
}