From 0df63036c888220ea2d5c122f3c19861b0959167 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Wed, 14 Sep 2011 01:39:02 +0200 Subject: Refined asprintf/vasprintf detection and inclusion --- src/asprintf.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/asprintf.h') diff --git a/src/asprintf.h b/src/asprintf.h index 6f1250d..3b0072e 100644 --- a/src/asprintf.h +++ b/src/asprintf.h @@ -1,15 +1,24 @@ #ifndef ASPRINTF_H #define ASPRINTF_H -#ifndef vasprintf + +#ifdef HAVE_CONFIG_H +#include +#endif + +#ifndef HAVE_VASPRINTF static inline int vasprintf(char **PTR, const char *TEMPLATE, va_list AP) { int res; - *PTR = (char*)malloc(512); - res = vsnprintf(*PTR, 512, TEMPLATE, AP); + res = vsnprintf(NULL, 32768, TEMPLATE, AP); + if (res > 0) { + *PTR = (char*)malloc(res+1); + res = vsnprintf(*PTR, res, TEMPLATE, AP); + } return res; } #endif -#ifndef asprintf + +#ifndef HAVE_ASPRINTF static inline int asprintf(char **PTR, const char *TEMPLATE, ...) { int res; @@ -20,4 +29,5 @@ static inline int asprintf(char **PTR, const char *TEMPLATE, ...) return res; } #endif -#endif + +#endif /* ASPRINTF_H */ -- cgit v1.1-32-gdbae