From 7a44e55045954ea0af06ab98ccfb41b18c1747f2 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 30 Sep 2010 01:28:11 -0400 Subject: mtd-utils: add xasprintf() helper Signed-off-by: Mike Frysinger Signed-off-by: Artem Bityutskiy --- include/xalloc.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'include/xalloc.h') 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 + +__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__ */ -- cgit v1.2.3