[ntpsec commit] Fix a NetBSD compiler warning, and refactor so surrounding code isn't ugly.

Eric S. Raymond esr at ntpsec.org
Wed Oct 21 08:48:40 UTC 2015


Module:    ntpsec
Branch:    master
Commit:    c0c25177e7f2ced1f8ff7f218a5c4066c8f76a11
Changeset: http://git.ntpsec.org/ntpsec/commit/?id=c0c25177e7f2ced1f8ff7f218a5c4066c8f76a11

Author:    Eric S. Raymond <esr at thyrsus.com>
Date:      Wed Oct 21 04:47:46 2015 -0400

Fix a NetBSD compiler warning, and refactor so surrounding code isn't ugly.

---

 include/ntp_fp.h    |  2 ++
 libntp/prettydate.c | 13 +++++++++++--
 ntptime/ntptime.c   |  3 +--
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/include/ntp_fp.h b/include/ntp_fp.h
index 16e7323..e97fcb2 100644
--- a/include/ntp_fp.h
+++ b/include/ntp_fp.h
@@ -347,6 +347,8 @@ extern  void	gpstolfp	(int, int, unsigned long, l_fp *);
 extern	bool	mstolfp		(const char *, l_fp *);
 extern	char *	prettydate	(l_fp *);
 extern	char *	gmprettydate	(l_fp *);
+extern	char *	gmprettydate	(l_fp *);
+extern	char *	rfc3339date	(l_fp *);
 extern	char *	uglydate	(l_fp *);
 extern  void	mfp_mul		(int32_t *, uint32_t *, int32_t, uint32_t, int32_t, uint32_t);
 
diff --git a/libntp/prettydate.c b/libntp/prettydate.c
index 9c87596..b52350d 100644
--- a/libntp/prettydate.c
+++ b/libntp/prettydate.c
@@ -125,7 +125,7 @@ common_prettydate(
 	static const char pfmt0[] =
 	    "%08lx.%08lx %04d-%02d-%02dT%02d:%02d:%02d.%03u";
 	static const char pfmt1[] =
-	    "%08lx.%08lx %04d-%02d-%02dT02d:%02d:%02d.%03uZ";
+	    "%08lx.%08lx %04d-%02d-%02dT%02d:%02d:%02d.%03uZ";
 
 	char	    *bp;
 	struct tm   *tm;
@@ -151,7 +151,7 @@ common_prettydate(
 		 */
 		struct calendar jd;
 		ntpcal_time_to_date(&jd, &sec);
-		snprintf(bp, LIB_BUFLENGTH, local ? pfmt1 : pfmt0,
+		snprintf(bp, LIB_BUFLENGTH, local ? pfmt0 : pfmt1,
 			 (u_long)ts->l_ui, (u_long)ts->l_uf,
 			 jd.year, jd.month, jd.monthday,
 			 jd.hour, jd.minute, jd.second, msec);
@@ -174,6 +174,15 @@ prettydate(
 
 
 char *
+rfc3339date(
+	l_fp *ts
+	)
+{
+    return common_prettydate(ts, false) + 18; /* skip past hex time */
+}
+
+
+char *
 gmprettydate(
 	l_fp *ts
 	)
diff --git a/ntptime/ntptime.c b/ntptime/ntptime.c
index fcf0324..67831a3 100644
--- a/ntptime/ntptime.c
+++ b/ntptime/ntptime.c
@@ -303,8 +303,7 @@ main(
 		ts.l_ui += JAN_1970;
 		ts.l_uf += ts_roundbit;
 		ts.l_uf &= ts_mask;
-		/* FIXME: ugly hack - we shouldn't use prettydate() here */
-		printf(json ? jfmt2 : ofmt2,  prettydate(&ts) + (json?18:0), fdigits, (int)time_frac);
+		printf(json ? jfmt2 : ofmt2,  json ? rfc3339date(&ts) : prettydate(&ts), fdigits, (int)time_frac);
 		printf(json ? jfmt3 : ofmt3,  (u_long)ntv.maxerror, (u_long)ntv.esterror);
 		if (rawtime)
 			printf(json ? jfmt4 : ofmt4,



More information about the vc mailing list