summaryrefslogtreecommitdiff
path: root/misc/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc/util.c')
-rw-r--r--misc/util.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/misc/util.c b/misc/util.c
new file mode 100644
index 0000000..0ca5e6b
--- /dev/null
+++ b/misc/util.c
@@ -0,0 +1,34 @@
+/*
+ * misc/util.c - Common utility functions
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#define _GNU_SOURCE /* for vasprintf */
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "misc/util.h"
+
+
+int alloc_printf(char **s, const char *fmt, ...)
+{
+ va_list ap;
+ int res;
+
+ va_start(ap, fmt);
+ res = vasprintf(s, fmt, ap);
+ va_end(ap);
+ if (res == -1) {
+ perror("vasprintf");
+ exit(1);
+ }
+ return res;
+}