Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

contrib.c: Added vasprintf/asprintf for windows.

  • Loading branch information...
commit 85d4eb508ebeaa2f72a12abae1502bceb6b8a4d7 1 parent 391cbbd
@orangea orangea authored
Showing with 30 additions and 0 deletions.
  1. +30 −0 core/contrib.c
View
30 core/contrib.c
@@ -5,6 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
+#include "config.h"
//
// wonderful utf-8 counting trickery
@@ -81,3 +82,32 @@ int potion_munmap(void *mem, size_t len)
}
#endif
+
+#if POTION_WIN32
+// vasprintf from nokogiri
+// http://github.com/tenderlove/nokogiri
+// (written by Geoffroy Couprie)
+int vasprintf (char **strp, const char *fmt, va_list ap)
+{
+ int len = vsnprintf (NULL, 0, fmt, ap) + 1;
+ char *res = (char *)malloc((unsigned int)len);
+ if (res == NULL)
+ return -1;
+ *strp = res;
+ return vsnprintf(res, (unsigned int)len, fmt, ap);
+}
+
+// asprintf from glibc
+int
+asprintf (char **string_ptr, const char *format, ...)
+{
+ va_list arg;
+ int done;
+
+ va_start (arg, format);
+ done = vasprintf (string_ptr, format, arg);
+ va_end (arg);
+
+ return done;
+}
+#endif
Please sign in to comment.
Something went wrong with that request. Please try again.