From 5671e632f834dbc8f16da66a1ad2c00928f5924c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 28 Apr 2001 12:27:37 +0000 Subject: got asprintf defn right (This used to be commit 531ab0917004cc1dbbdc4a2b6b8d41f354dd2da7) --- source3/lib/snprintf.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'source3') diff --git a/source3/lib/snprintf.c b/source3/lib/snprintf.c index 18afb2f793..ce7c4a68f5 100644 --- a/source3/lib/snprintf.c +++ b/source3/lib/snprintf.c @@ -76,7 +76,12 @@ #include #endif -#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) || !defined(HAVE_C99_VSNPRINTF) +#if defined(HAVE_SNPRINTF) && defined(HAVE_VSNPRINTF) && defined(HAVE_C99_VSNPRINTF) +/* only include stdio.h if we are not re-defining snprintf or vsnprintf */ +#include + /* make the compiler happy with an empty file */ + void dummy_snprintf(void) {} +#else #ifdef HAVE_LONG_DOUBLE #define LDOUBLE long double @@ -728,32 +733,28 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) } #endif -#else - /* make the compiler happy with an empty file */ - void dummy_snprintf(void); #endif #ifndef HAVE_ASPRINTF - char *asprintf(const char *format, ...) + int asprintf(char **ptr, const char *format, ...) { va_list ap; int ret; - char *str; va_start(ap, format); ret = vsnprintf(NULL, 0, format, ap); va_end(ap); - if (ret == -1) return NULL; + if (ret <= 0) return ret; va_start(ap, format); - str = (char *)malloc(ret+1); - if (!str) return NULL; - ret = vsnprintf(str, ret+1, format, ap); + (*ptr) = (char *)malloc(ret+1); + if (!*ptr) return -1; + ret = vsnprintf(*ptr, ret+1, format, ap); va_end(ap); - return str; + return ret; } #endif -- cgit