summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/xprintf_time.c
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2011-03-06 17:43:32 +0000
committerpjd <pjd@FreeBSD.org>2011-03-06 17:43:32 +0000
commit3d9241706267e9b042c64d362f9c0f5ce1c4e8db (patch)
treea33d3c3f108a67f276bf91b2885f7b43d7a8fd4a /lib/libc/stdio/xprintf_time.c
parent2868a01f090039809e0244134ca187edb2dcee80 (diff)
downloadFreeBSD-src-3d9241706267e9b042c64d362f9c0f5ce1c4e8db.zip
FreeBSD-src-3d9241706267e9b042c64d362f9c0f5ce1c4e8db.tar.gz
Fix various issues in how %#T is handled:
- If precision is 0, don't print period followed by no digits. - If precision is 0 stop printing units as soon as possible (eg. if we have three years and five days and precision is 0 print only 3y5d). - If precision is not 0, print all units (eg. 3y0d0h0m0s.00). MFC after: 2 weeks
Diffstat (limited to 'lib/libc/stdio/xprintf_time.c')
-rw-r--r--lib/libc/stdio/xprintf_time.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/libc/stdio/xprintf_time.c b/lib/libc/stdio/xprintf_time.c
index 9d732fe..c80681e 100644
--- a/lib/libc/stdio/xprintf_time.c
+++ b/lib/libc/stdio/xprintf_time.c
@@ -80,6 +80,12 @@ __printf_render_time(struct __printf_io *io, const struct printf_info *pi, const
nsec = 0;
prec = 0;
}
+ if (pi->is_long || pi->is_long_double) {
+ if (pi->prec >= 0)
+ prec = pi->prec;
+ if (prec == 0)
+ nsec = 0;
+ }
p = buf;
if (pi->alt) {
@@ -88,26 +94,24 @@ __printf_render_time(struct __printf_io *io, const struct printf_info *pi, const
p += sprintf(p, "%jdy", t / YEAR);
t %= YEAR;
}
- if (t >= DAY && t != 0) {
+ if (tx >= DAY && (t != 0 || prec != 0)) {
p += sprintf(p, "%jdd", t / DAY);
t %= DAY;
}
- if (t >= HOUR && t != 0) {
+ if (tx >= HOUR && (t != 0 || prec != 0)) {
p += sprintf(p, "%jdh", t / HOUR);
t %= HOUR;
}
- if (t >= MINUTE && t != 0) {
+ if (tx >= MINUTE && (t != 0 || prec != 0)) {
p += sprintf(p, "%jdm", t / MINUTE);
t %= MINUTE;
}
- if (t != 0 || tx == 0)
+ if (t != 0 || tx == 0 || prec != 0)
p += sprintf(p, "%jds", t);
} else {
p += sprintf(p, "%jd", (intmax_t)t);
}
- if (pi->is_long || pi->is_long_double) {
- if (pi->prec >= 0)
- prec = pi->prec;
+ if (prec != 0) {
for (i = prec; i < 9; i++)
nsec /= 10;
p += sprintf(p, ".%.*d", prec, nsec);
OpenPOWER on IntegriCloud