summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/xprintf_time.c
diff options
context:
space:
mode:
authorhrs <hrs@FreeBSD.org>2011-05-29 02:53:52 +0000
committerhrs <hrs@FreeBSD.org>2011-05-29 02:53:52 +0000
commit8fe640108653f13042f1b15213769e338aa524f6 (patch)
tree91f5675a7c792e61d68635707501027daa3f566f /lib/libc/stdio/xprintf_time.c
parent97f64b711efa9ff0011bef5d46cf9645638a38f9 (diff)
parentf3726238c8e8206eb1df4cfaf3f00947ceba3cce (diff)
downloadFreeBSD-src-8fe640108653f13042f1b15213769e338aa524f6.zip
FreeBSD-src-8fe640108653f13042f1b15213769e338aa524f6.tar.gz
Merge from head@222434.
Diffstat (limited to 'lib/libc/stdio/xprintf_time.c')
-rw-r--r--lib/libc/stdio/xprintf_time.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/libc/stdio/xprintf_time.c b/lib/libc/stdio/xprintf_time.c
index 9d732fe..debfac5 100644
--- a/lib/libc/stdio/xprintf_time.c
+++ b/lib/libc/stdio/xprintf_time.c
@@ -62,7 +62,7 @@ __printf_render_time(struct __printf_io *io, const struct printf_info *pi, const
struct timespec *ts;
time_t *tp;
intmax_t t, tx;
- int i, prec, nsec;
+ int i, prec, nsec, ret;
if (pi->is_long) {
tv = *((struct timeval **)arg[0]);
@@ -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,29 +94,29 @@ __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);
}
- return(__printf_out(io, pi, buf, p - buf));
+ ret = __printf_out(io, pi, buf, p - buf);
+ __printf_flush(io);
+ return (ret);
}
OpenPOWER on IntegriCloud