diff options
author | Jesse Luehrs <doy@tozt.net> | 2016-05-01 22:21:46 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2016-05-01 22:21:46 -0400 |
commit | 957ef4d81438a74d530f2a3890bfcd0145c11fd9 (patch) | |
tree | 6354b666ed05aea2f4bdd2b4e749230843d107a3 /src/util.c | |
parent | a2b9833253748ca113cc101c60867fd7e1dca64d (diff) | |
download | runes-957ef4d81438a74d530f2a3890bfcd0145c11fd9.tar.gz runes-957ef4d81438a74d530f2a3890bfcd0145c11fd9.zip |
simplify
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; +} |