Enabled g_mem_set_vtable through the configure option --with-overridable-allocators...
[mono.git] / eglib / src / vasprintf.c
index 96921645b69172403b60fde9f9cb3c0d726fce40..72820b8e961af577cc0aea2c3dc3bdd66355a62f 100644 (file)
@@ -1,30 +1,32 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <glib.h>
 
-int vasprintf(char **ret, const char *fmt, va_list ap)
+gint g_vasprintf (gchar **ret, const gchar *fmt, va_list ap)
 {
-char *buf;
-int len;
-size_t buflen;
-va_list ap2;
-
-#ifdef _MSC_VER
-ap2 = ap;
-len = _vscprintf(fmt, ap2); // NOTE MS specific extension ( :-( )
+       char *buf;
+       int len;
+       size_t buflen;
+       va_list ap2;
+       
+#if defined(_MSC_VER) || defined(__MINGW64_VERSION_MAJOR)
+       ap2 = ap;
+       len = _vscprintf(fmt, ap2); // NOTE MS specific extension ( :-( )
 #else
-va_copy(ap2, ap);
-len = vsnprintf(NULL, 0, fmt, ap2);
+       va_copy(ap2, ap);
+       len = vsnprintf(NULL, 0, fmt, ap2);
 #endif
-
-if (len > 0 && (buf = malloc((buflen = (size_t) (len + 1)))) != NULL) {
-len = vsnprintf(buf, buflen, fmt, ap);
-*ret = buf;
-} else {
-*ret = NULL;
-len = -1;
+       
+       if (len >= 0 && (buf = g_malloc ((buflen = (size_t) (len + 1)))) != NULL) {
+               len = vsnprintf(buf, buflen, fmt, ap);
+               *ret = buf;
+       } else {
+               *ret = NULL;
+               len = -1;
+       }
+       
+       va_end(ap2);
+       return len;
 }
 
-va_end(ap2);
-return len;
-}