aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2016-05-01 22:21:46 -0400
committerJesse Luehrs <doy@tozt.net>2016-05-01 22:21:46 -0400
commit957ef4d81438a74d530f2a3890bfcd0145c11fd9 (patch)
tree6354b666ed05aea2f4bdd2b4e749230843d107a3 /src/util.c
parenta2b9833253748ca113cc101c60867fd7e1dca64d (diff)
downloadrunes-957ef4d81438a74d530f2a3890bfcd0145c11fd9.tar.gz
runes-957ef4d81438a74d530f2a3890bfcd0145c11fd9.zip
simplify
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;
+}