tools/nolibc/stdio: make printf(%s) accept NULL

It's often convenient to support this, especially in test programs where
a NULL may correspond to an allocation error or a non-existing value.
Let's make printf("%s") support being passed a NULL. In this case it
prints "(null)" like glibc's printf().

Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
This commit is contained in:
Willy Tarreau 2022-03-21 18:33:07 +01:00 committed by Paul E. McKenney
parent f0f04f28d5
commit 170b230d22
1 changed files with 2 additions and 0 deletions

View File

@ -220,6 +220,8 @@ int vfprintf(FILE *stream, const char *fmt, va_list args)
}
else if (c == 's') {
outstr = va_arg(args, char *);
if (!outstr)
outstr="(null)";
}
else if (c == '%') {
/* queue it verbatim */