From: Thomas Weißschuh Date: Fri, 11 Apr 2025 09:00:52 +0000 (+0200) Subject: selftests/nolibc: use snprintf() for printf tests X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=c685cd6db59cc4557c93538677a8bdaa05f49fbc;p=users%2Fhch%2Fmisc.git selftests/nolibc: use snprintf() for printf tests With a proper snprintf() implementation in place, the ugly pipe usage is not necessary anymore. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 64f88b492029..1874199b2cf6 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1299,27 +1299,14 @@ int run_stdlib(int min, int max) static int expect_vfprintf(int llen, int c, const char *expected, const char *fmt, ...) { - int ret, pipefd[2]; - ssize_t w, r; char buf[100]; - FILE *memfile; va_list args; + ssize_t w; + int ret; - ret = pipe(pipefd); - if (ret == -1) { - llen += printf(" pipe() != %s", strerror(errno)); - result(llen, FAIL); - return 1; - } - - memfile = fdopen(pipefd[1], "w"); - if (!memfile) { - result(llen, FAIL); - return 1; - } va_start(args, fmt); - w = vfprintf(memfile, fmt, args); + w = vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); if (w != c) { @@ -1328,17 +1315,6 @@ static int expect_vfprintf(int llen, int c, const char *expected, const char *fm return 1; } - fclose(memfile); - - r = read(pipefd[0], buf, sizeof(buf) - 1); - - if (r != w) { - llen += printf(" written(%d) != read(%d)", (int)w, (int)r); - result(llen, FAIL); - return 1; - } - - buf[r] = '\0'; llen += printf(" \"%s\" = \"%s\"", expected, buf); ret = strncmp(expected, buf, c);