summaryrefslogtreecommitdiff
path: root/lib/libc/stdio/vasprintf.c
diff options
context:
space:
mode:
authorKacper <kacper@mail.openlinux.dev>2025-12-07 20:10:31 +0100
committerKacper <kacper@mail.openlinux.dev>2025-12-07 20:10:31 +0100
commitfc00c656c96528112d05cf0edf8631bd5eaea446 (patch)
treea6e0e6c588191a8bd1c64afc3b7a258e3e66c236 /lib/libc/stdio/vasprintf.c
Add build system scaffolding and libc headers
Diffstat (limited to 'lib/libc/stdio/vasprintf.c')
-rw-r--r--lib/libc/stdio/vasprintf.c18
1 files changed, 18 insertions, 0 deletions
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 <io.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+// 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);
+}