Skip to content

Commit

Permalink
contrib.c: Added vasprintf/asprintf for windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
orangea committed Nov 7, 2010
1 parent 391cbbd commit 85d4eb5
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions core/contrib.c
Expand Up @@ -5,6 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include "config.h"


// //
// wonderful utf-8 counting trickery // wonderful utf-8 counting trickery
Expand Down Expand Up @@ -81,3 +82,32 @@ int potion_munmap(void *mem, size_t len)
} }


#endif #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

0 comments on commit 85d4eb5

Please sign in to comment.