Date: Tue, 29 Mar 2011 17:52:45 +0000 (UTC) From: Mikolaj Golub <trociny@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r220138 - stable/8/lib/libc/stdio Message-ID: <201103291752.p2THqjeF036028@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: trociny Date: Tue Mar 29 17:52:45 2011 New Revision: 220138 URL: http://svn.freebsd.org/changeset/base/220138 Log: MFC r219342, r219346: r219342 (pjd): 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). r219346 (pjd): Because we call __printf_out() with a on-stack buffer, also call __printf_flush() so we are sure it won't be referenced after we return. Approved by: kib (co-mentor), pjd (mentor) Modified: stable/8/lib/libc/stdio/xprintf_time.c Directory Properties: stable/8/lib/libc/ (props changed) stable/8/lib/libc/stdtime/ (props changed) Modified: stable/8/lib/libc/stdio/xprintf_time.c ============================================================================== --- stable/8/lib/libc/stdio/xprintf_time.c Tue Mar 29 17:47:25 2011 (r220137) +++ stable/8/lib/libc/stdio/xprintf_time.c Tue Mar 29 17:52:45 2011 (r220138) @@ -62,7 +62,7 @@ __printf_render_time(struct __printf_io struct timespec *ts; time_t *tp; intmax_t t, tx; - int i, prec, nsec; + int i, prec, nsec, ret; prec = 0; if (pi->is_long) { @@ -79,6 +79,12 @@ __printf_render_time(struct __printf_io tp = *((time_t **)arg[0]); t = *tp; } + 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) { @@ -87,29 +93,29 @@ __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); } - return(__printf_out(io, pi, buf, p - buf)); + ret = __printf_out(io, pi, buf, p - buf); + __printf_flush(io); + return (ret); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201103291752.p2THqjeF036028>