From fc00c656c96528112d05cf0edf8631bd5eaea446 Mon Sep 17 00:00:00 2001 From: Kacper Date: Sun, 7 Dec 2025 20:10:31 +0100 Subject: Add build system scaffolding and libc headers --- lib/libc/stdio/vasprintf.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lib/libc/stdio/vasprintf.c (limited to 'lib/libc/stdio/vasprintf.c') diff --git a/lib/libc/stdio/vasprintf.c b/lib/libc/stdio/vasprintf.c new file mode 100644 index 00000000..128d4ee3 --- /dev/null +++ b/lib/libc/stdio/vasprintf.c @@ -0,0 +1,18 @@ +#include +#include +#include + +// TODO: maybe use memstream in future?? +int vasprintf(char **restrict ptr, const char *restrict format, va_list ap) +{ + int l; + va_list ap2; + va_copy(ap2, ap); + l = vsnprintf(0, 0, format, ap2); + va_end(ap2); + + if (l < 0 || !(*ptr = malloc(l + 1U))) + return -1; + + return vsnprintf(*ptr, l + 1U, format, ap); +} -- cgit v1.2.3