diff options
author | Werner Almesberger <werner@almesberger.net> | 2016-09-11 18:00:58 -0300 |
---|---|---|
committer | Werner Almesberger <werner@almesberger.net> | 2016-09-11 18:00:58 -0300 |
commit | 275f91f0728393365de8cb37881656d137844688 (patch) | |
tree | bdc14b0ce0c27d4ab73db2badcacd711cc6b7ee3 /misc | |
parent | c71736dd1f5c897840c2083777cdc326f97581c7 (diff) | |
download | eeshow-275f91f0728393365de8cb37881656d137844688.tar.gz eeshow-275f91f0728393365de8cb37881656d137844688.tar.bz2 eeshow-275f91f0728393365de8cb37881656d137844688.zip |
misc/util.c: add alloc_vprintf
Diffstat (limited to 'misc')
-rw-r--r-- | misc/util.c | 18 | ||||
-rw-r--r-- | misc/util.h | 3 |
2 files changed, 17 insertions, 4 deletions
diff --git a/misc/util.c b/misc/util.c index 0ca5e6b..628270d 100644 --- a/misc/util.c +++ b/misc/util.c @@ -18,17 +18,27 @@ #include "misc/util.h" -int alloc_printf(char **s, const char *fmt, ...) +int alloc_vprintf(char **s, const char *fmt, va_list ap) { - va_list ap; int res; - va_start(ap, fmt); res = vasprintf(s, fmt, ap); - va_end(ap); if (res == -1) { perror("vasprintf"); exit(1); } return res; } + + + +int alloc_printf(char **s, const char *fmt, ...) +{ + va_list ap; + int res; + + va_start(ap, fmt); + res = alloc_vprintf(s, fmt, ap); + va_end(ap); + return res; +} diff --git a/misc/util.h b/misc/util.h index 5c195f1..ebc0762 100644 --- a/misc/util.h +++ b/misc/util.h @@ -14,6 +14,7 @@ #ifndef MISC_UTIL_H #define MISC_UTIL_H +#include <stdarg.h> #include <stdbool.h> #include <stdlib.h> #include <stdio.h> @@ -71,6 +72,8 @@ static inline bool strbegins(const char *s, const char *prefix) } +int alloc_vprintf(char **s, const char *fmt, va_list ap) + __attribute__((format(printf, 2, 0))); int alloc_printf(char **s, const char *fmt, ...) __attribute__((format(printf, 2, 3))); |