Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/dmesg Allow a third use of -T to force .NNN (always thr...



details:   https://anonhg.NetBSD.org/src/rev/83c589f4a301
branches:  trunk
changeset: 433539:83c589f4a301
user:      kre <kre%NetBSD.org@localhost>
date:      Wed Sep 19 22:58:03 2018 +0000

description:
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.

diffstat:

 sbin/dmesg/dmesg.c |  16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

diffs (51 lines):

diff -r c5f7837eb749 -r 83c589f4a301 sbin/dmesg/dmesg.c
--- a/sbin/dmesg/dmesg.c        Wed Sep 19 22:55:12 2018 +0000
+++ b/sbin/dmesg/dmesg.c        Wed Sep 19 22:58:03 2018 +0000
@@ -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 @@
 #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 @@
        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 @@
        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 @@
                                        }
                                } else if (humantime > 1) {
                                        const char *fp = fmtydhmsf(tbuf,
-                                           sizeof(tbuf), sec, fsec);
+                                           sizeof(tbuf), sec, fsec, humantime);
                                        if (fp) {
                                                printf("%s", fp);
                                        }



Home | Main Index | Thread Index | Old Index