diff options
author | CNLohr <charles@cnlohr.com> | 2017-03-16 15:30:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-16 15:30:21 -0400 |
commit | d9412e4252c176583b5b737608acb4e60d47c00a (patch) | |
tree | c339acbb982d1f2d67977be98a4ae7cac85f8057 /redist/json_helpers.c | |
parent | 6daf2506fcfbfcd26d63a8bddba319d67ecc33e5 (diff) | |
parent | ccaa625c6161e14f5c2281cc43134d1928094620 (diff) | |
download | libsurvive-d9412e4252c176583b5b737608acb4e60d47c00a.tar.gz libsurvive-d9412e4252c176583b5b737608acb4e60d47c00a.tar.bz2 |
Merge pull request #37 from mwturvey/WinSupport2
VS2017 CE Support
Diffstat (limited to 'redist/json_helpers.c')
-rw-r--r-- | redist/json_helpers.c | 38 |
1 files changed, 37 insertions, 1 deletions
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 <string.h> #include "json_helpers.h" #include <jsmn.h> +#include <malloc.h> +#ifdef _WIN32 +#include <stdarg.h> + +// 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<size;++i) { t = tokens+i; |