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 <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
This commit is contained in:
Thomas Weißschuh
2025-04-11 11:00:52 +02:00
committed by Thomas Weißschuh
parent ed45d24cf2
commit c685cd6db5

View File

@@ -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);