[PATCH 2/3] mtd-utils: add xasprintf() helper

Mike Frysinger vapier at gentoo.org
Thu Sep 30 01:28:11 EDT 2010


Signed-off-by: Mike Frysinger <vapier at gentoo.org>
---
v2
	- use shorter "die" func

 include/xalloc.h |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/include/xalloc.h b/include/xalloc.h
index 5d145d9..d49a1ae 100644
--- a/include/xalloc.h
+++ b/include/xalloc.h
@@ -77,4 +77,24 @@ static char *xstrdup(const char *s)
 	return t;
 }
 
+#ifdef _GNU_SOURCE
+#include <stdarg.h>
+
+__attribute__((unused))
+static int xasprintf(char **strp, const char *fmt, ...)
+{
+	int cnt;
+	va_list ap;
+
+	va_start(ap, fmt);
+	cnt = vasprintf(strp, fmt, ap);
+	va_end(ap);
+
+	if (cnt == -1)
+		sys_errmsg_die("asprintf(...) failed");
+
+	return cnt;
+}
+#endif
+
 #endif /* !__MTD_UTILS_XALLOC_H__ */
-- 
1.7.2.3




More information about the linux-mtd mailing list