[PATCH v2 next 11/11] selftests/nolibc: Use printf("%.*s", n, "") to align output

From: david . laight . linux

Date: Fri Feb 06 2026 - 14:18:55 EST


From: David Laight <david.laight.linux@xxxxxxxxx>

Now that printf supports '*' for field widths it can be used to
align the "[OK]" strings in the output.

Signed-off-by: David Laight <david.laight.linux@xxxxxxxxx>
---

Changes for v2:
- Formally patch 12, unchanged.

tools/testing/selftests/nolibc/nolibc-test.c | 21 ++++----------------
1 file changed, 4 insertions(+), 17 deletions(-)

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 10ae6dcd71b8..416d0fd8d85e 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -141,21 +141,6 @@ static const char *errorname(int err)
}
}

-static void align_result(size_t llen)
-{
- const size_t align = 64;
- char buf[align];
- size_t n;
-
- if (llen >= align)
- return;
-
- n = align - llen;
- memset(buf, ' ', n);
- buf[n] = '\0';
- fputs(buf, stdout);
-}
-
enum RESULT {
OK,
FAIL,
@@ -173,8 +158,10 @@ static void result(int llen, enum RESULT r)
else
msg = " [FAIL]";

- align_result(llen);
- puts(msg);
+ llen = 64 - llen;
+ if (llen < 0)
+ llen = 0;
+ printf("%*s%s\n", llen, "", msg);
}

/* The tests below are intended to be used by the macroes, which evaluate
--
2.39.5