aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Luis Duran <jlduran@gmail.com>2022-10-14 23:26:32 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2022-10-25 21:40:17 +0000
commit947efadc3d6e778a824618d82f53f061bec69b77 (patch)
treec9958dfc8f268312e84042401a26b9c022a7c7b3
parent6da51e19e347c13e133bcba68cc6100c16320a01 (diff)
downloadsrc-947efadc3d6e778a824618d82f53f061bec69b77.tar.gz
src-947efadc3d6e778a824618d82f53f061bec69b77.zip
-rw-r--r--lib/libc/stdlib/strfmon.c12
-rw-r--r--lib/libc/tests/stdlib/strfmon_test.c4
2 files changed, 12 insertions, 4 deletions
diff --git a/lib/libc/stdlib/strfmon.c b/lib/libc/stdlib/strfmon.c
index a7a48317c97c..80a73ee28916 100644
--- a/lib/libc/stdlib/strfmon.c
+++ b/lib/libc/stdlib/strfmon.c
@@ -373,8 +373,12 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc,
PRINTS(signstr);
}
- if (sign_posn == 0 && (flags & IS_NEGATIVE))
- PRINT(')');
+ if (sign_posn == 0) {
+ if (flags & IS_NEGATIVE)
+ PRINT(')');
+ else if (left_prec >= 0)
+ PRINT(' ');
+ }
if (dst - tmpptr < width) {
if (flags & LEFT_JUSTIFY) {
@@ -466,6 +470,10 @@ __calc_left_pad(int flags, char *cur_symb)
}
switch (sign_posn) {
+ case 0:
+ if (flags & IS_NEGATIVE)
+ left_chars++;
+ break;
case 1:
left_chars += strlen(signstr);
break;
diff --git a/lib/libc/tests/stdlib/strfmon_test.c b/lib/libc/tests/stdlib/strfmon_test.c
index b5b22f9a483d..d4d1f6a580d9 100644
--- a/lib/libc/tests/stdlib/strfmon_test.c
+++ b/lib/libc/tests/stdlib/strfmon_test.c
@@ -81,8 +81,8 @@ ATF_TC_BODY(strfmon_examples, tc)
{ "%^#5n", "[ $ 123.45] [-$ 123.45] [ $ 3456.78]" },
{ "%^#5.0n", "[ $ 123] [-$ 123] [ $ 3457]" },
{ "%^#5.4n", "[ $ 123.4500] [-$ 123.4500] [ $ 3456.7810]" },
- { "%(#5n", "[$ 123.45] [($ 123.45)] [$ 3,456.78]" }, /* XXX */
- { "%!(#5n", "[ 123.45] [( 123.45)] [ 3,456.78]" }, /* XXX */
+ { "%(#5n", "[ $ 123.45 ] [($ 123.45)] [ $ 3,456.78 ]" },
+ { "%!(#5n", "[ 123.45 ] [( 123.45)] [ 3,456.78 ]" },
{ "%-14#5.4n", "[ $ 123.4500 ] [-$ 123.4500 ] [ $ 3,456.7810 ]" },
{ "%14#5.4n", "[ $ 123.4500] [ -$ 123.4500] [ $ 3,456.7810]" },
};