[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v2 1/5] lib/nolibc: import asprintf from musl



From: Costin Lupu <costin.lupu@xxxxxxxxx>

Copied as it is from official musl git mirror
(git://git.musl-libc.org/musl)

Commit <f2c6dbe2442027ed8fe0fa869918e41f495534d8>

Original file locations:
- src/stdio/asprintf.c
- src/stdio/vasprintf.c

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
Reviewed-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>
---
 lib/nolibc/asprintf.c  | 13 +++++++++++++
 lib/nolibc/vasprintf.c | 15 +++++++++++++++
 2 files changed, 28 insertions(+)
 create mode 100644 lib/nolibc/asprintf.c
 create mode 100644 lib/nolibc/vasprintf.c

diff --git a/lib/nolibc/asprintf.c b/lib/nolibc/asprintf.c
new file mode 100644
index 0000000..4ec8353
--- /dev/null
+++ b/lib/nolibc/asprintf.c
@@ -0,0 +1,13 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdarg.h>
+
+int asprintf(char **s, const char *fmt, ...)
+{
+       int ret;
+       va_list ap;
+       va_start(ap, fmt);
+       ret = vasprintf(s, fmt, ap);
+       va_end(ap);
+       return ret;
+}
diff --git a/lib/nolibc/vasprintf.c b/lib/nolibc/vasprintf.c
new file mode 100644
index 0000000..08251bc
--- /dev/null
+++ b/lib/nolibc/vasprintf.c
@@ -0,0 +1,15 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+int vasprintf(char **s, const char *fmt, va_list ap)
+{
+       va_list ap2;
+       va_copy(ap2, ap);
+       int l = vsnprintf(0, 0, fmt, ap2);
+       va_end(ap2);
+
+       if (l<0 || !(*s=malloc(l+1U))) return -1;
+       return vsnprintf(*s, l+1U, fmt, ap);
+}
-- 
2.17.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.