Module Name:    src
Committed By:   kre
Date:           Wed Sep 19 22:58:03 UTC 2018

Modified Files:
        src/sbin/dmesg: dmesg.c

Log Message:
Allow a third use of -T to force .NNN (always three digits) in -TT
(ISO8601 durations) format for timestamps - that is,not dropping trailing 0's.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sbin/dmesg/dmesg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/dmesg/dmesg.c
diff -u src/sbin/dmesg/dmesg.c:1.35 src/sbin/dmesg/dmesg.c:1.36
--- src/sbin/dmesg/dmesg.c:1.35	Wed Sep 19 22:55:12 2018
+++ src/sbin/dmesg/dmesg.c	Wed Sep 19 22:58:03 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: dmesg.c,v 1.35 2018/09/19 22:55:12 kre Exp $	*/
+/*	$NetBSD: dmesg.c,v 1.36 2018/09/19 22:58:03 kre Exp $	*/
 /*-
  * Copyright (c) 1991, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -38,7 +38,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19
 #if 0
 static char sccsid[] = "@(#)dmesg.c	8.1 (Berkeley) 6/5/93";
 #else
-__RCSID("$NetBSD: dmesg.c,v 1.35 2018/09/19 22:55:12 kre Exp $");
+__RCSID("$NetBSD: dmesg.c,v 1.36 2018/09/19 22:58:03 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -71,7 +71,7 @@ __dead static void	usage(void);
 	kvm_read(kd, addr, &var, sizeof(var)) != sizeof(var)
 
 static const char *
-fmtydhmsf(char *b, size_t l, intmax_t t, long nsec)
+fmtydhmsf(char *b, size_t l, intmax_t t, long nsec, int ht)
 {
 	intmax_t s, m, h, d, M, y;
 	int z;
@@ -126,9 +126,11 @@ fmtydhmsf(char *b, size_t l, intmax_t t,
 	if (nsec)
 		nsec = (nsec + 500000) / 1000000;	/* now milliseconds */
 	prec = 3;
-	while (prec > 0 && (nsec % 10) == 0)
-		--prec, nsec /= 10;
-	if (nsec)
+	if (nsec && ht == 2) {
+		while (prec > 0 && (nsec % 10) == 0)
+			--prec, nsec /= 10;
+	}
+	if (nsec || ht > 2)
 		APPENDS(s, prec, nsec);
 	else
 		APPEND(s);
@@ -345,7 +347,7 @@ main(int argc, char *argv[])
 					}
 				} else if (humantime > 1) {
 					const char *fp = fmtydhmsf(tbuf,
-					    sizeof(tbuf), sec, fsec);
+					    sizeof(tbuf), sec, fsec, humantime);
 					if (fp) {
 						printf("%s", fp);
 					}

Reply via email to