svn commit: r219342 - head/lib/libc/stdio
Pawel Jakub Dawidek
pjd at FreeBSD.org
Sun Mar 6 17:43:33 UTC 2011
Author: pjd
Date: Sun Mar 6 17:43:32 2011
New Revision: 219342
URL: http://svn.freebsd.org/changeset/base/219342
Log:
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
Modified:
head/lib/libc/stdio/xprintf_time.c
Modified: head/lib/libc/stdio/xprintf_time.c
==============================================================================
--- head/lib/libc/stdio/xprintf_time.c Sun Mar 6 16:10:39 2011 (r219341)
+++ head/lib/libc/stdio/xprintf_time.c Sun Mar 6 17:43:32 2011 (r219342)
@@ -80,6 +80,12 @@ __printf_render_time(struct __printf_io
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
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);
More information about the svn-src-head
mailing list