mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-08 10:50:28 +00:00
Implement S conversion specifier for printf-related functions
POSIX specifies that a conversion specifier of S must be interpreted the same way as %ls. This patch implements this.
This commit is contained in:
parent
58b2f9bd6b
commit
edabba4fbb
2 changed files with 9 additions and 0 deletions
|
@ -359,10 +359,15 @@ _Hide int __fmt(void *fn, void *arg, const char *format, va_list va) {
|
|||
p = "\r\e[K";
|
||||
goto FormatString;
|
||||
}
|
||||
case 'S':
|
||||
// Specified by POSIX to be equivalent to %ls
|
||||
signbit = 63;
|
||||
goto FormatStringPNotFetchedYet;
|
||||
case 'q':
|
||||
flags |= FLAGS_QUOTE;
|
||||
// fallthrough
|
||||
case 's':
|
||||
FormatStringPNotFetchedYet:
|
||||
p = va_arg(va, void *);
|
||||
FormatString:
|
||||
if (__fmt_stoa(out, arg, p, flags, prec, width, signbit, qchar) == -1) {
|
||||
|
|
|
@ -64,6 +64,10 @@ TEST(fmt, d) {
|
|||
EXPECT_STREQ("-2147483648", _gc(xasprintf("% d", INT_MIN)));
|
||||
}
|
||||
|
||||
TEST(fmt, s) {
|
||||
EXPECT_STREQ("Wide character output test", _gc(xasprintf("%S", L"Wide character output test")));
|
||||
}
|
||||
|
||||
TEST(fmt, g) {
|
||||
EXPECT_STREQ("1", _gc(xasprintf("%g", 1.)));
|
||||
EXPECT_STREQ(" 1", _gc(xasprintf("% g", 1.)));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue