From 7b8644dcc1a0db95c3ea321ebb8bc059ab931b42 Mon Sep 17 00:00:00 2001 From: Richard Nyberg Date: Mon, 12 Jan 2009 22:09:26 +0100 Subject: Provide own implementation of asprintf if it's missing. --- misc/subr.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'misc/subr.c') diff --git a/misc/subr.c b/misc/subr.c index 5b5261e..b90af81 100644 --- a/misc/subr.c +++ b/misc/subr.c @@ -14,6 +14,8 @@ #include #include +#include "subr.h" + void * memfind(const void *sub, size_t sublen, const void *mem, size_t memlen) { @@ -443,3 +445,21 @@ end: out[oi] = '\0'; return 0; } + +#ifndef HAVE_ASPRINTF +int +asprintf(char **strp, const char *fmt, ...) +{ + int np; + va_list ap; + va_start(ap, fmt); + np = vsnprintf(NULL, 0, fmt, ap); + va_end(ap); + if ((*strp = malloc(np + 1)) == NULL) + return -1; + va_start(ap, fmt); + vsnprintf(*strp, np + 1, fmt, ap); + va_end(ap); + return np; +} +#endif -- cgit 1.4.1