]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
tools/nolibc/printf: Add support for octal output
authorDavid Laight <david.laight.linux@gmail.com>
Sun, 8 Mar 2026 11:37:41 +0000 (11:37 +0000)
committerThomas Weißschuh <linux@weissschuh.net>
Fri, 20 Mar 2026 16:58:24 +0000 (17:58 +0100)
commit248c7cf60c808f09044af1ce1d2c7c707696dc1e
tree929a0a4103d5923b1c9c9f8350cdd58b3108430b
parentd3d3f64f8e964f8af6ac72294e65caad5acc452e
tools/nolibc/printf: Add support for octal output

Octal output isn't often used, but adding it costs very little.

Supporting "%#o" is mildly annoying, it has to add a leading '0' if
there isn't one present. In simple cases this is the same as adding a sign
of '0' - but that adds an extra '0' in a few places.
So you need 3 tests, %o, # and no leading '0' (which can only be checked
after the zero pad for precision).
If all the test are deferred until after zero padding then too many values
are 'live' across the call to _nolibc_u64toa_base() and get spilled to stack.
Hence the check that ignores the 'sign' if it is the same as the first
character of the output string.

Add tests for octal output.

Signed-off-by: David Laight <david.laight.linux@gmail.com>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://patch.msgid.link/20260308113742.12649-17-david.laight.linux@gmail.com
[Thomas: avoid a -Wsign-compare]
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
tools/include/nolibc/stdio.h
tools/testing/selftests/nolibc/nolibc-test.c