summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authorjkim <jkim@FreeBSD.org>2010-07-08 22:13:23 +0000
committerjkim <jkim@FreeBSD.org>2010-07-08 22:13:23 +0000
commit93b88a93dabf70976640d9a81668eacdfa35891c (patch)
tree914ed90bc05367bf9e90c13b3a3c3a98c55f33cd /sys/kern
parente80a867ba425a418f2ac6a6b13be063d656a360b (diff)
downloadFreeBSD-src-93b88a93dabf70976640d9a81668eacdfa35891c.zip
FreeBSD-src-93b88a93dabf70976640d9a81668eacdfa35891c.tar.gz
Implement optional 'precision' for numbers. Previously, it was parsed but
ignored. Some third-party modules (e.g., APCICA) prefer this format over zero padding flag '0'.
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/subr_prf.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c
index 30e92cb..776c4e8 100644
--- a/sys/kern/subr_prf.c
+++ b/sys/kern/subr_prf.c
@@ -800,7 +800,8 @@ number:
neg = 1;
num = -(intmax_t)num;
}
- p = ksprintn(nbuf, num, base, &tmp, upper);
+ p = ksprintn(nbuf, num, base, &n, upper);
+ tmp = 0;
if (sharpflag && num != 0) {
if (base == 8)
tmp++;
@@ -810,10 +811,13 @@ number:
if (neg)
tmp++;
- if (!ladjust && padc != '0' && width
- && (width -= tmp) > 0)
- while (width--)
- PCHAR(padc);
+ if (!ladjust && padc == '0')
+ dwidth = width - tmp;
+ width -= tmp + MAX(dwidth, n);
+ dwidth -= n;
+ if (!ladjust)
+ while (width-- > 0)
+ PCHAR(' ');
if (neg)
PCHAR('-');
if (sharpflag && num != 0) {
@@ -824,16 +828,15 @@ number:
PCHAR('x');
}
}
- if (!ladjust && width && (width -= tmp) > 0)
- while (width--)
- PCHAR(padc);
+ while (dwidth-- > 0)
+ PCHAR('0');
while (*p)
PCHAR(*p--);
- if (ladjust && width && (width -= tmp) > 0)
- while (width--)
- PCHAR(padc);
+ if (ladjust)
+ while (width-- > 0)
+ PCHAR(' ');
break;
default:
OpenPOWER on IntegriCloud