Module Name: src
Committed By: kre
Date: Wed Sep 19 22:55:12 UTC 2018
Modified Files:
src/sbin/dmesg: dmesg.c
Log Message:
In -TT mode (ISO8601 duration timestamps) print milliseconds as
decimal fractions of a second (as they should be) rather than integer
milliseconds (ie nnn.1means nnn seconds and 1/10 of a second, not
nnn seconds, and 1 millisecond). While here convert some inappropriate
time_t usage to intmax_t which works better (int, or long, would probably
work just as well).
To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 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.34 src/sbin/dmesg/dmesg.c:1.35
--- src/sbin/dmesg/dmesg.c:1.34 Wed Sep 19 00:15:05 2018
+++ src/sbin/dmesg/dmesg.c Wed Sep 19 22:55:12 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: dmesg.c,v 1.34 2018/09/19 00:15:05 christos Exp $ */
+/* $NetBSD: dmesg.c,v 1.35 2018/09/19 22:55:12 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.34 2018/09/19 00:15:05 christos Exp $");
+__RCSID("$NetBSD: dmesg.c,v 1.35 2018/09/19 22:55:12 kre Exp $");
#endif
#endif /* not lint */
@@ -71,10 +71,11 @@ __dead static void usage(void);
kvm_read(kd, addr, &var, sizeof(var)) != sizeof(var)
static const char *
-fmtydhmsf(char *b, size_t l, time_t t, long nsec)
+fmtydhmsf(char *b, size_t l, intmax_t t, long nsec)
{
- time_t s, m, h, d, M, y;
+ intmax_t s, m, h, d, M, y;
int z;
+ int prec;
size_t o;
s = t % 60;
@@ -109,10 +110,10 @@ fmtydhmsf(char *b, size_t l, time_t t, l
#define APPEND(a) \
do if (a) \
- APPENDFMT("%jd%c", (intmax_t)a, toupper((unsigned char)__STRING(a)[0])); \
+ APPENDFMT("%jd%c", a, toupper((unsigned char)__STRING(a)[0])); \
while (/*CONSTCOND*/0)
-#define APPENDS(a, s) \
- APPENDFMT("%jd.%ld%c", (intmax_t)a, s, \
+#define APPENDS(a, pr, ms) \
+ APPENDFMT("%jd%s%.*ld%c", a, radix, pr, ms, \
toupper((unsigned char)__STRING(a)[0]))
APPENDFMT("%s", "P");
@@ -123,9 +124,12 @@ fmtydhmsf(char *b, size_t l, time_t t, l
APPEND(h);
APPEND(m);
if (nsec)
- nsec = nsec / 1000000;
+ nsec = (nsec + 500000) / 1000000; /* now milliseconds */
+ prec = 3;
+ while (prec > 0 && (nsec % 10) == 0)
+ --prec, nsec /= 10;
if (nsec)
- APPENDS(s, nsec);
+ APPENDS(s, prec, nsec);
else
APPEND(s);
return b;