From 66f330d94f6777d4cb8bac1e429b13dffd320745 Mon Sep 17 00:00:00 2001 From: otto <> Date: Tue, 27 Mar 2007 18:22:02 +0000 Subject: [PATCH] Normalize tv so that tv_usec is positive. The kernel also normalizes, but this might increase portability since some other systems do not grok negative tv_usec well. ok henning@ --- src/usr.sbin/ntpd/util.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/usr.sbin/ntpd/util.c b/src/usr.sbin/ntpd/util.c index 68468710..10075076 100644 --- a/src/usr.sbin/ntpd/util.c +++ b/src/usr.sbin/ntpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.12 2006/10/27 12:22:41 henning Exp $ */ +/* $OpenBSD: util.c,v 1.13 2007/03/27 18:22:02 otto Exp $ */ /* * Copyright (c) 2004 Alexander Guy @@ -64,6 +64,10 @@ d_to_tv(double d, struct timeval *tv) { tv->tv_sec = (long)d; tv->tv_usec = (d - tv->tv_sec) * 1000000; + while (tv->tv_usec < 0) { + tv->tv_usec += 1000000; + tv->tv_sec -= 1; + } } double