kprintf(9): Implement optional 'precision' for numbers.
authorSascha Wildner <saw@online.de>
Thu, 3 Jan 2013 18:14:38 +0000 (19:14 +0100)
committerSascha Wildner <saw@online.de>
Thu, 3 Jan 2013 18:15:23 +0000 (19:15 +0100)
Previously, it was parsed but ignored. Some third-party modules
(e.g., APCICA) prefer this format over zero padding flag '0'.

Before this commit:

ACPI Warning: 32/64X FACS address mismatch in FADT - 0x3F611E40/0x       03F611D40, using 32 (20110527/tbfadt-589)

After this commit:

ACPI Warning: 32/64X FACS address mismatch in FADT - 0x3F611E40/0x000000003F611D40, using 32 (20110527/tbfadt-589)

Taken-from: FreeBSD (r209836 and r209949)

sys/kern/subr_prf.c

index 867fcf7..9c5f040 100644 (file)
@@ -840,7 +840,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++;
@@ -850,11 +851,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 + imax(dwidth, n);
+                       dwidth -= n;
+                       if (!ladjust)
+                               while (width-- > 0)
+                                       PCHAR(' ');
                        if (neg)
                                PCHAR('-');
                        if (sharpflag && num != 0) {
@@ -865,16 +868,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: