1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-27 22:50:26 +03:00

got asprintf defn right

(This used to be commit 531ab0917004cc1dbbdc4a2b6b8d41f354dd2da7)
This commit is contained in:
Andrew Tridgell 2001-04-28 12:27:37 +00:00
parent 3a44e2364b
commit 5671e632f8

View File

@ -76,7 +76,12 @@
#include <stdlib.h>
#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 <stdio.h>
/* 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