[PATCH 01/16] xfuncs: add xasprintf() and xvasprintf()

Michael Olbrich m.olbrich at pengutronix.de
Fri Jul 17 12:22:34 PDT 2015


Signed-off-by: Michael Olbrich <m.olbrich at pengutronix.de>
---
 include/xfuncs.h |  3 +++
 lib/xfuncs.c     | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/include/xfuncs.h b/include/xfuncs.h
index 8efc99dbc455..c7c0203f375b 100644
--- a/include/xfuncs.h
+++ b/include/xfuncs.h
@@ -2,6 +2,7 @@
 #define __XFUNCS_H
 
 #include <linux/types.h>
+#include <stdarg.h>
 
 void *xmalloc(size_t size);
 void *xrealloc(void *ptr, size_t size);
@@ -9,5 +10,7 @@ void *xzalloc(size_t size);
 char *xstrdup(const char *s);
 void* xmemalign(size_t alignment, size_t bytes);
 void* xmemdup(const void *orig, size_t size);
+char *xasprintf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
+char *xvasprintf(const char *fmt, va_list ap);
 
 #endif /* __XFUNCS_H */
diff --git a/lib/xfuncs.c b/lib/xfuncs.c
index 0e78b670a5d4..ce89169547a4 100644
--- a/lib/xfuncs.c
+++ b/lib/xfuncs.c
@@ -81,3 +81,27 @@ void *xmemdup(const void *orig, size_t size)
 	return buf;
 }
 EXPORT_SYMBOL(xmemdup);
+
+char *xvasprintf(const char *fmt, va_list ap)
+{
+	char *p;
+
+	p = vasprintf(fmt, ap);
+	if (!p)
+		panic("ERROR: out of memory\n");
+	return p;
+}
+EXPORT_SYMBOL(xvasprintf)
+
+char *xasprintf(const char *fmt, ...)
+{
+	va_list ap;
+	char *p;
+
+	va_start(ap, fmt);
+	p = xvasprintf(fmt, ap);
+	va_end(ap);
+
+	return p;
+}
+EXPORT_SYMBOL(xasprintf);
-- 
2.1.4




More information about the barebox mailing list