summaryrefslogtreecommitdiffstats
path: root/usr.sbin/nsd/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/nsd/util.c')
-rw-r--r--usr.sbin/nsd/util.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/usr.sbin/nsd/util.c b/usr.sbin/nsd/util.c
index ff54eda72b2..db3d7ceddce 100644
--- a/usr.sbin/nsd/util.c
+++ b/usr.sbin/nsd/util.c
@@ -393,6 +393,28 @@ write_socket(int s, const void *buf, size_t size)
return 1;
}
+void get_time(struct timespec* t)
+{
+ struct timeval tv;
+#ifdef HAVE_CLOCK_GETTIME
+ /* first try nanosecond precision */
+ if(clock_gettime(CLOCK_REALTIME, t)>=0) {
+ return; /* success */
+ }
+ log_msg(LOG_ERR, "clock_gettime: %s", strerror(errno));
+#endif
+ /* try millisecond precision */
+ if(gettimeofday(&tv, NULL)>=0) {
+ t->tv_sec = tv.tv_sec;
+ t->tv_nsec = tv.tv_usec*1000;
+ return; /* success */
+ }
+ log_msg(LOG_ERR, "gettimeofday: %s", strerror(errno));
+ /* whole seconds precision */
+ t->tv_sec = time(0);
+ t->tv_nsec = 0;
+}
+
int
timespec_compare(const struct timespec *left,
const struct timespec *right)