diff options
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -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; +} |