]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tools/nolibc/printf: Add support for conversion flags space and plus
authorDavid Laight <david.laight.linux@gmail.com>
Sun, 8 Mar 2026 11:37:37 +0000 (11:37 +0000)
committerThomas Weißschuh <linux@weissschuh.net>
Fri, 20 Mar 2026 16:55:52 +0000 (17:55 +0100)
Flags ' ' and '+' are sign characters for positive numbers.

Signed-off-by: David Laight <david.laight.linux@gmail.com>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://patch.msgid.link/20260308113742.12649-13-david.laight.linux@gmail.com
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
tools/include/nolibc/stdio.h

index 3620aa643c814e180dffce6c7dc43e5b91159eb6..65e113f135d451baf97229e0d0f0b411d75c367d 100644 (file)
@@ -296,7 +296,7 @@ int fseek(FILE *stream, long offset, int whence)
  *  - %% generates a single %
  *  - %m outputs strerror(errno).
  *  - %X outputs a..f the same as %x.
- *  - The modifiers [#-0] are currently ignored.
+ *  - The modifiers [#-0] are currently ignored.
  *  - No support for precision or variable widths.
  *  - No support for floating point or wide characters.
  *  - Invalid formats are copied to the output buffer.
@@ -457,6 +457,10 @@ int __nolibc_printf(__nolibc_printf_cb cb, void *state, const char *fmt, va_list
                                        sign_prefix = '-';
                                        v = -(signed_v + 1);
                                        v++;
+                               } else if (_NOLIBC_PF_FLAGS_CONTAIN(flags, '+')) {
+                                       sign_prefix = '+';
+                               } else if (_NOLIBC_PF_FLAGS_CONTAIN(flags, ' ')) {
+                                       sign_prefix = ' ';
                                }
                        }