aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index d87fd72..686f02d 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,5 +1,6 @@
#include <stdarg.h>
#include <stdio.h>
+#include <stdlib.h>
#include "runes.h"
@@ -11,3 +12,21 @@ void runes_warn(const char *fmt, ...)
vfprintf(stderr, fmt, ap);
va_end(ap);
}
+
+int sprintf_dup(char **out, const char *fmt, ...)
+{
+ int outlen = 0;
+ va_list ap;
+
+ va_start(ap, fmt);
+ outlen = vsnprintf(*out, outlen, fmt, ap);
+ va_end(ap);
+
+ *out = malloc(outlen + 1);
+
+ va_start(ap, fmt);
+ outlen = vsnprintf(*out, outlen + 1, fmt, ap);
+ va_end(ap);
+
+ return outlen;
+}