summaryrefslogtreecommitdiff
path: root/usr.sbin/rdate
diff options
context:
space:
mode:
authorJakob Schlyter <jakob@cvs.openbsd.org>2002-07-31 12:48:47 +0000
committerJakob Schlyter <jakob@cvs.openbsd.org>2002-07-31 12:48:47 +0000
commitad981859971c5f9bfd2ece4d07e4b5fd33ec4c25 (patch)
treeaa9b4ac335432664a1a088f09e63a2ec2ebce3ed /usr.sbin/rdate
parenta6d4786f0d6839f7b3cb34bb77744b9932b73197 (diff)
minor changes and knf from thorsten glaser
Diffstat (limited to 'usr.sbin/rdate')
-rw-r--r--usr.sbin/rdate/ntp.c9
-rw-r--r--usr.sbin/rdate/ntpleaps.c6
-rw-r--r--usr.sbin/rdate/ntpleaps.h6
3 files changed, 13 insertions, 8 deletions
diff --git a/usr.sbin/rdate/ntp.c b/usr.sbin/rdate/ntp.c
index 9cf2a823a6a..e8a14c8426c 100644
--- a/usr.sbin/rdate/ntp.c
+++ b/usr.sbin/rdate/ntp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntp.c,v 1.10 2002/07/28 07:48:29 jakob Exp $ */
+/* $OpenBSD: ntp.c,v 1.11 2002/07/31 12:48:46 jakob Exp $ */
/*
* Copyright (c) 1996, 1997 by N.M. Maclaren. All rights reserved.
@@ -447,15 +447,16 @@ current_time(double offset)
if (gettimeofday(&current, NULL))
err(1, "Could not get local time of day");
- /* At this point, current has the current TAI time.
+ /*
+ * At this point, current has the current TAI time.
* Now subtract leap seconds to set the posix tick.
*/
- t = NTPLEAPS_OFFSET + (u_int64_t) current.tv_sec;
+ t = SEC_TO_TAI64(current.tv_sec);
if (corrleaps)
ntpleaps_sub(&t);
- return offset + ( t - NTPLEAPS_OFFSET ) + 1.0e-6 * current.tv_usec;
+ return offset + TAI64_TO_SEC(t) + 1.0e-6 * current.tv_usec;
}
/*
diff --git a/usr.sbin/rdate/ntpleaps.c b/usr.sbin/rdate/ntpleaps.c
index 39d83a6ab72..f697008994c 100644
--- a/usr.sbin/rdate/ntpleaps.c
+++ b/usr.sbin/rdate/ntpleaps.c
@@ -1,4 +1,4 @@
-/* $Id: ntpleaps.c,v 1.2 2002/07/30 23:28:14 deraadt Exp $ */
+/* $OpenBSD: ntpleaps.c,v 1.3 2002/07/31 12:48:46 jakob Exp $ */
/*
* Copyright (c) 2002 by Thorsten "mirabile" Glaser <x86@ePOST.de>
@@ -21,7 +21,7 @@
/* Leap second support for NTP clients (generic) */
-static const char RCSId[] = "$OpenBSD: ntpleaps.c,v 1.2 2002/07/30 23:28:14 deraadt Exp $";
+static const char RCSId[] = "$OpenBSD: ntpleaps.c,v 1.3 2002/07/31 12:48:46 jakob Exp $";
/* I could include tzfile.h, but this would make the code unportable
@@ -144,7 +144,7 @@ ntpleaps_read(void)
for (m1 = 0; m1 < r; m1++) {
read(fd, buf, 8);
m2 = ntohl(*((u_int32_t *)buf));
- s = NTPLEAPS_OFFSET + (u_int64_t)m2;
+ s = SEC_TO_TAI64(m2);
/*
* Assume just _one_ leap second on each entry, and compensate
* the lacking error checking by validating the first entry
diff --git a/usr.sbin/rdate/ntpleaps.h b/usr.sbin/rdate/ntpleaps.h
index eb5fef167ed..c0d733d169e 100644
--- a/usr.sbin/rdate/ntpleaps.h
+++ b/usr.sbin/rdate/ntpleaps.h
@@ -1,4 +1,4 @@
-/* $Id: ntpleaps.h,v 1.1 2002/07/27 08:46:51 jakob Exp $ */
+/* $OpenBSD: ntpleaps.h,v 1.2 2002/07/31 12:48:46 jakob Exp $ */
/*
* Copyright (c) 2002 by Thorsten "mirabile" Glaser <x86@ePOST.de>
@@ -37,6 +37,10 @@
/* Offset between struct timeval.tv_sec and a tai64_t */
#define NTPLEAPS_OFFSET (4611686018427387914ULL)
+/* Hide this ugly value from programmes */
+#define SEC_TO_TAI64(s) (NTPLEAPS_OFFSET + (u_int64_t)(s))
+#define TAI64_TO_SEC(t) ((t) - NTPLEAPS_OFFSET)
+
/* Initializes the leap second table. Does not need to be called
* before usage of the subtract funtion, but calls ntpleaps_read.
* returns 0 on success, -1 on error (displays a warning on stderr)