summaryrefslogtreecommitdiffstats
path: root/include/xalloc.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/xalloc.h')
-rw-r--r--include/xalloc.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/xalloc.h b/include/xalloc.h
index feeb1144f..8c22ff76a 100644
--- a/include/xalloc.h
+++ b/include/xalloc.h
@@ -63,4 +63,15 @@ static inline char *xstrdup(const char *str)
return ret;
}
+static inline int xasprintf(char **strp, char *fmt, ...)
+{
+ int ret;
+ va_list args;
+ va_start(args, fmt);
+ ret = vasprintf(&(*strp), fmt, args);
+ va_end(args);
+ if (ret < 0)
+ err(XALLOC_EXIT_CODE, "cannot allocate string");
+ return ret;
+}
#endif