Windows version added

This commit is contained in:
2015-10-26 09:51:00 +01:00
parent b09d347e6b
commit 898bab4492
+22 -9
View File
@@ -2,21 +2,34 @@
#include <stdlib.h>
#include "asprintf.h"
#ifndef va_copy
#define va_copy __va_copy
#endif
int vasprintf(char** pbuffer, const char* format, va_list ap)
{
va_list ap2;
int len;
FILE* f;
size_t len;
#if defined(vxWorks)
FILE* f;
/* print to null device to get required buffer length */
f = fopen("/null","w");
if (f == NULL) return -1;
__va_copy(ap2, ap);
len = vfprintf(f, format, ap2);
if ((f = fopen("/null","w")) != NULL)
{
len = vfprintf(f, format, ap2);
fclose(f);
}
#elif defined(_WIN32)
len = _vscprintf(format, ap);
#else
len = vsnprintf(NULL, 0, format, ap);
#endif
va_end(ap2);
fclose(f);
if (len < 0) return len;
if (len <= 0)
{
fprintf(stderr, "vasprintf: too old version on vsnprintf\n");
return len;
}
*pbuffer = malloc(len+1);
if (*pbuffer == NULL) return -1;
return vsprintf(*pbuffer, format, ap);