1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-20 11:11:24 +00:00

When padding with zero, do pad after prefixes rather than padding

before prefixes.

Use cases:
	printf("%05d", -42);   -->   "00-42"   (should be "-0042")
	printf("%#05x", 12);   -->   "000xc"   (should be "0x00c")

Submitted by:	Oliver Fromme
PR:		kern/85520
MFC After:	1 week
This commit is contained in:
Xin LI 2005-09-04 18:03:45 +00:00
parent 245c31ccaf
commit 5248ef8a3c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=149784

View File

@ -755,7 +755,8 @@ reswitch: switch (ch = (u_char)*fmt++) {
if (neg)
tmp++;
if (!ladjust && width && (width -= tmp) > 0)
if (!ladjust && padc != '0' && width
&& (width -= tmp) > 0)
while (width--)
PCHAR(padc);
if (neg)
@ -768,6 +769,9 @@ reswitch: switch (ch = (u_char)*fmt++) {
PCHAR('x');
}
}
if (!ladjust && width && (width -= tmp) > 0)
while (width--)
PCHAR(padc);
while (*p)
PCHAR(*p--);