aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/stdio/printf-pos.c
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2026-11-15 16:37:42 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2026-11-15 17:16:55 +0000
commit5e809bf1c93fdc4c52fa46a7eb0e6f881b6c6140 (patch)
tree6aff862af4feb54d8943344773a232d3520677eb /lib/libc/stdio/printf-pos.c
parent0e3fce268adeec8f4c87b99759dae6a592b3d365 (diff)
stdio: Fix positional %wN / %wfN conversion
MFC after: 1 week Fixes: bce0bef3c6ab ("libc: Implement N2680.") Fixes: 12b1c1e3fb44 ("libc: Add test cases for N2680.")
Diffstat (limited to 'lib/libc/stdio/printf-pos.c')
-rw-r--r--lib/libc/stdio/printf-pos.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/libc/stdio/printf-pos.c b/lib/libc/stdio/printf-pos.c
index 27b59f25b67d..fd92b3d5ad29 100644
--- a/lib/libc/stdio/printf-pos.c
+++ b/lib/libc/stdio/printf-pos.c
@@ -337,6 +337,40 @@ reswitch: switch (ch) {
case 't':
flags |= PTRDIFFT;
goto rflag;
+ case 'w':
+ flags &= ~(CHARINT|SHORTINT|LONGINT|LLONGINT|INTMAXT);
+ if (fmt[0] == 'f') {
+ flags |= FASTINT;
+ fmt++;
+ } else {
+ flags &= ~FASTINT;
+ }
+ if (fmt[0] == '8') {
+ if (!(flags & FASTINT))
+ flags |= CHARINT;
+ else
+ /* no flag set = 32 */ ;
+ fmt += 1;
+ } else if (fmt[0] == '1' && fmt[1] == '6') {
+ if (!(flags & FASTINT))
+ flags |= SHORTINT;
+ else
+ /* no flag set = 32 */ ;
+ fmt += 2;
+ } else if (fmt[0] == '3' && fmt[1] == '2') {
+ /* no flag set = 32 */ ;
+ fmt += 2;
+ } else if (fmt[0] == '6' && fmt[1] == '4') {
+ flags |= LLONGINT;
+ fmt += 2;
+ } else {
+ if (flags & FASTINT) {
+ flags &= ~FASTINT;
+ fmt--;
+ }
+ goto error;
+ }
+ goto rflag;
case 'z':
flags |= SIZET;
goto rflag;
@@ -532,6 +566,40 @@ reswitch: switch (ch) {
case 't':
flags |= PTRDIFFT;
goto rflag;
+ case 'w':
+ flags &= ~(CHARINT|SHORTINT|LONGINT|LLONGINT|INTMAXT);
+ if (fmt[0] == 'f') {
+ flags |= FASTINT;
+ fmt++;
+ } else {
+ flags &= ~FASTINT;
+ }
+ if (fmt[0] == '8') {
+ if (!(flags & FASTINT))
+ flags |= CHARINT;
+ else
+ /* no flag set = 32 */ ;
+ fmt += 1;
+ } else if (fmt[0] == '1' && fmt[1] == '6') {
+ if (!(flags & FASTINT))
+ flags |= SHORTINT;
+ else
+ /* no flag set = 32 */ ;
+ fmt += 2;
+ } else if (fmt[0] == '3' && fmt[1] == '2') {
+ /* no flag set = 32 */ ;
+ fmt += 2;
+ } else if (fmt[0] == '6' && fmt[1] == '4') {
+ flags |= LLONGINT;
+ fmt += 2;
+ } else {
+ if (flags & FASTINT) {
+ flags &= ~FASTINT;
+ fmt--;
+ }
+ goto error;
+ }
+ goto rflag;
case 'z':
flags |= SIZET;
goto rflag;