From 1caa844dad647b03cf3c1d11bf211e9fcde4b7f1 Mon Sep 17 00:00:00 2001 From: mwturvey Date: Wed, 15 Mar 2017 11:38:22 -0700 Subject: Windows Compiling --- redist/json_helpers.c | 38 +++++++++++++++++++++++++++++++++++++- redist/os_generic.h | 2 +- 2 files changed, 38 insertions(+), 2 deletions(-) (limited to 'redist') diff --git a/redist/json_helpers.c b/redist/json_helpers.c index 4a3ba55..2413a67 100644 --- a/redist/json_helpers.c +++ b/redist/json_helpers.c @@ -7,7 +7,42 @@ #include #include "json_helpers.h" #include +#include +#ifdef _WIN32 +#include + +// Windows doesn't provide asprintf, so we need to make it. +int asprintf(char **strp, const char *fmt, ...) +{ + char* buff = NULL; + va_list listPointer; + va_start( listPointer, fmt ); + + size_t lenNeeded = _vscprintf(fmt, listPointer) + 1; // add one for a terminating null + + if (lenNeeded > 1) + { + buff = (char*)malloc(lenNeeded); + if (buff) + { + int bytesWritten = _vsnprintf(buff, lenNeeded, fmt, listPointer); + if (bytesWritten < 0) + { + free(buff); + buff = NULL; + } + } + } + + if (strp) + { + *strp = buff; + } + return (int)lenNeeded; +} + +#endif void json_write_float_array(FILE* f, const char* tag, float* v, uint8_t count) { uint8_t i = 0; @@ -101,7 +136,8 @@ static uint16_t json_load_array(const char* JSON_STRING, jsmntok_t* tokens, uint jsmntok_t* t = tokens; uint16_t i = 0; - char* values[size]; + char** values; + values = alloca(sizeof(char*) * size); for (i=0;i