summaryrefslogtreecommitdiff
path: root/include/xalloc.h
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2010-09-30 01:28:11 -0400
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2010-09-30 08:54:46 +0300
commit7a44e55045954ea0af06ab98ccfb41b18c1747f2 (patch)
tree567ffc0878f07edc1c6f90cc240250166512c097 /include/xalloc.h
parentb2dc086600f64d5a2db179fb6bed79a0a78228e4 (diff)
mtd-utils: add xasprintf() helper
Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'include/xalloc.h')
-rw-r--r--include/xalloc.h20
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__ */