| @@ -31,13 +31,7 @@ | |||||
| #include "json_util.h" | #include "json_util.h" | ||||
| #include "math_compat.h" | #include "math_compat.h" | ||||
| #include "strdup_compat.h" | #include "strdup_compat.h" | ||||
| #if !defined(HAVE_SNPRINTF) && defined(_MSC_VER) | |||||
| /* MSC has the version as _snprintf */ | |||||
| # define snprintf _snprintf | |||||
| #elif !defined(HAVE_SNPRINTF) | |||||
| # error You do not have snprintf on your system. | |||||
| #endif /* HAVE_SNPRINTF */ | |||||
| #include "snprintf_compat.h" | |||||
| // Don't define this. It's not thread-safe. | // Don't define this. It's not thread-safe. | ||||
| /* #define REFCOUNT_DEBUG 1 */ | /* #define REFCOUNT_DEBUG 1 */ | ||||
| @@ -48,12 +48,7 @@ | |||||
| # define open _open | # define open _open | ||||
| #endif | #endif | ||||
| #if !defined(HAVE_SNPRINTF) && defined(_MSC_VER) | |||||
| /* MSC has the version as _snprintf */ | |||||
| # define snprintf _snprintf | |||||
| #elif !defined(HAVE_SNPRINTF) | |||||
| # error You do not have snprintf on your system. | |||||
| #endif /* HAVE_SNPRINTF */ | |||||
| #include "snprintf_compat.h" | |||||
| #include "debug.h" | #include "debug.h" | ||||
| #include "printbuf.h" | #include "printbuf.h" | ||||
| @@ -27,6 +27,7 @@ | |||||
| #include "debug.h" | #include "debug.h" | ||||
| #include "printbuf.h" | #include "printbuf.h" | ||||
| #include "snprintf_compat.h" | |||||
| #include "vasprintf_compat.h" | #include "vasprintf_compat.h" | ||||
| static int printbuf_extend(struct printbuf *p, int min_size); | static int printbuf_extend(struct printbuf *p, int min_size); | ||||
| @@ -0,0 +1,36 @@ | |||||
| #ifndef __snprintf_compat_h | |||||
| #define __snprintf_compat_h | |||||
| /* | |||||
| * Microsoft's _vsnprintf and _snprint don't always terminate | |||||
| * the string, so use wrappers that ensure that. | |||||
| */ | |||||
| #include <stdarg.h> | |||||
| #if !defined(HAVE_SNPRINTF) && defined(_MSC_VER) | |||||
| static int json_c_vsnprintf(char *str, size_t size, const char *format, va_list ap) | |||||
| { | |||||
| int ret; | |||||
| ret = _vsnprintf(str, size, format, ap); | |||||
| str[size - 1] = '\0'; | |||||
| return ret; | |||||
| } | |||||
| #define vsnprintf json_c_vsnprintf | |||||
| static int json_c_snprintf(char *str, size_t size, const char *format, ...) | |||||
| { | |||||
| va_list ap; | |||||
| int ret; | |||||
| va_start(ap, format); | |||||
| ret = json_c_vsnprintf(str, size, format, ap); | |||||
| va_end(ap); | |||||
| return ret; | |||||
| } | |||||
| #define snprintf json_c_snprintf | |||||
| #elif !defined(HAVE_SNPRINTF) /* !HAVE_SNPRINTF */ | |||||
| # error Need vsnprintf! | |||||
| #endif /* !HAVE_SNPRINTF && defined(WIN32) */ | |||||
| #endif /* __snprintf_compat_h */ | |||||
| @@ -7,6 +7,7 @@ | |||||
| #include "config.h" | #include "config.h" | ||||
| #include "json.h" | #include "json.h" | ||||
| #include "json_tokener.h" | #include "json_tokener.h" | ||||
| #include "snprintf_compat.h" | |||||
| #ifdef HAVE_LOCALE_H | #ifdef HAVE_LOCALE_H | ||||
| #include <locale.h> | #include <locale.h> | ||||
| @@ -1,11 +1,7 @@ | |||||
| #ifndef __vasprintf_compat_h | #ifndef __vasprintf_compat_h | ||||
| #define __vasprintf_compat_h | #define __vasprintf_compat_h | ||||
| #if !defined(HAVE_VSNPRINTF) && defined(_MSC_VER) | |||||
| # define vsnprintf _vsnprintf | |||||
| #elif !defined(HAVE_VSNPRINTF) /* !HAVE_VSNPRINTF */ | |||||
| # error Need vsnprintf! | |||||
| #endif /* !HAVE_VSNPRINTF && defined(WIN32) */ | |||||
| #include "snprintf_compat.h" | |||||
| #if !defined(HAVE_VASPRINTF) | #if !defined(HAVE_VASPRINTF) | ||||
| /* CAW: compliant version of vasprintf */ | /* CAW: compliant version of vasprintf */ | ||||