summaryrefslogtreecommitdiff
path: root/lib/libc/stdio/vasprintf.c
diff options
context:
space:
mode:
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);
+}