summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/utils.c30
1 files changed, 4 insertions, 26 deletions
diff --git a/src/utils.c b/src/utils.c
index 415924a..14446fc 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1564,39 +1564,17 @@ void print_todo(const char *format, struct todo *todo)
}
}
-#define VASPRINTF_INITIAL_BUFSIZE 128
-
-int
-vasprintf(char **str, const char *format, va_list ap)
-{
- va_list ap2;
- int n;
-
- va_copy(ap2, ap);
-
- *str = mem_malloc(VASPRINTF_INITIAL_BUFSIZE);
- n = vsnprintf(*str, VASPRINTF_INITIAL_BUFSIZE, format, ap);
- if (n >= VASPRINTF_INITIAL_BUFSIZE) {
- *str = mem_realloc(*str, 1, n + 1);
- n = vsnprintf(*str, n + 1, format, ap2);
- }
-
- if (n < 0) {
- mem_free(*str);
- *str = NULL;
- }
-
- return n;
-}
-
int
asprintf(char **str, const char *format, ...)
{
+ struct string s;
va_list ap;
int n;
va_start(ap, format);
- n = vasprintf(str, format, ap);
+ string_init(&s);
+ n = string_vcatf(&s, format, ap);
+ *str = string_buf(&s);
va_end(ap);
return n;