From 957ef4d81438a74d530f2a3890bfcd0145c11fd9 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 1 May 2016 22:21:46 -0400 Subject: simplify --- src/util.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/util.c') 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 #include +#include #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; +} -- cgit v1.2.3-54-g00ecf