]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
tools/nolibc/printf: Support negative variable width and precision
authorDavid Laight <david.laight.linux@gmail.com>
Mon, 23 Mar 2026 11:22:47 +0000 (11:22 +0000)
committerThomas Weißschuh <linux@weissschuh.net>
Wed, 1 Apr 2026 16:02:37 +0000 (18:02 +0200)
commit1dff9ac2c85860af67a74777fa6d31c2ad07a15a
tree1001788e66cf14e2255e0aee59f188d2dd8c9484
parent6285f0881ec68034399d13552f7243e69e6e37bf
tools/nolibc/printf: Support negative variable width and precision

For (eg) "%*.*s" treat a negative field width as a request to left align
the output (the same as the '-' flag), and a negative precision to
request the default precision.

Set the default precision to -1 (not INT_MAX) and add explicit checks
to the string handling for negative values (makes the tet unsigned).

For numeric output check for 'precision >= 0' instead of testing
_NOLIBC_PF_FLAGS_CONTAIN(flags, '.').
This needs an inverted test, some extra goto and removes an indentation.
The changed conditionals fix printf("%0-#o", 0) - but '0' and '-' shouldn't
both be specified.

Signed-off-by: David Laight <david.laight.linux@gmail.com>
Link: https://patch.msgid.link/20260323112247.3196-1-david.laight.linux@gmail.com
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
tools/include/nolibc/stdio.h
tools/testing/selftests/nolibc/nolibc-test.c