summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2001-04-28 12:27:37 +0000
committerAndrew Tridgell <tridge@samba.org>2001-04-28 12:27:37 +0000
commit5671e632f834dbc8f16da66a1ad2c00928f5924c (patch)
tree71769d10c3f48a8fbceb04fee01e16ee515eb364 /source3
parent3a44e2364b546adb9e9c166e0b8ae6a0b4894b70 (diff)
downloadsamba-5671e632f834dbc8f16da66a1ad2c00928f5924c.tar.gz
samba-5671e632f834dbc8f16da66a1ad2c00928f5924c.tar.bz2
samba-5671e632f834dbc8f16da66a1ad2c00928f5924c.zip
got asprintf defn right
(This used to be commit 531ab0917004cc1dbbdc4a2b6b8d41f354dd2da7)
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/snprintf.c23
1 files changed, 12 insertions, 11 deletions
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 <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