diff options
author | Thomas Weißschuh <thomas.weissschuh@linutronix.de> | 2025-04-11 11:00:47 +0200 |
---|---|---|
committer | Thomas Weißschuh <linux@weissschuh.net> | 2025-04-22 10:58:22 +0200 |
commit | 5197b7b87cbfeed61b69ff54532bb58a0d55cb0b (patch) | |
tree | 16fd8a7ae1fad98e7a70da5dbb4dff4c9cf1f5e1 | |
parent | 4175b5584510faa8acbfa98103781c36780d5a79 (diff) |
tools/nolibc: add dprintf() and vdprintf()
dprintf() and vdprintf() are printf() variants printing directly into a
filedescriptor. As FILE in nolibc is based directly on filedescriptors,
the implementation is trivial.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
-rw-r--r-- | tools/include/nolibc/stdio.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index b32b8b794015..262d0da4da90 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -351,6 +351,30 @@ int printf(const char *fmt, ...) return ret; } +static __attribute__((unused, format(printf, 2, 0))) +int vdprintf(int fd, const char *fmt, va_list args) +{ + FILE *stream; + + stream = fdopen(fd, NULL); + if (!stream) + return -1; + /* Technically 'stream' is leaked, but as it's only a wrapper around 'fd' that is fine */ + return vfprintf(stream, fmt, args); +} + +static __attribute__((unused, format(printf, 2, 3))) +int dprintf(int fd, const char *fmt, ...) +{ + va_list args; + int ret; + + va_start(args, fmt); + ret = vdprintf(fd, fmt, args); + va_end(args); + return ret; +} + static __attribute__((unused)) int vsscanf(const char *str, const char *format, va_list args) { |