diff --git a/arraylist.c b/arraylist.c index 9a673d6..2d44a18 100644 --- a/arraylist.c +++ b/arraylist.c @@ -11,12 +11,12 @@ #include "config.h" -#if STDC_HEADERS +#ifdef STDC_HEADERS # include # include #endif /* STDC_HEADERS */ -#if defined HAVE_STRINGS_H && !defined _STRING_H && !defined __USE_BSD +#if defined(HAVE_STRINGS_H) && !defined(_STRING_H) && !defined(__USE_BSD) # include #endif /* HAVE_STRINGS_H */ diff --git a/json_object.c b/json_object.c index 5a35938..2258c02 100644 --- a/json_object.c +++ b/json_object.c @@ -26,7 +26,14 @@ #include "json_object_private.h" #include "json_util.h" -#if !HAVE_STRNDUP +#if !defined(HAVE_STRDUP) && defined(_MSC_VER) + /* MSC has the version as _strdup */ +# define strdup _strdup +#elif !defined(HAVE_STRDUP) +# error You do not have strdup on your system. +#endif /* HAVE_STRDUP */ + +#if !defined(HAVE_STRNDUP) char* strndup(const char* str, size_t n); #endif /* !HAVE_STRNDUP */ @@ -531,7 +538,7 @@ struct json_object* json_object_new_string_len(const char *s, int len) if(!jso) return NULL; jso->_delete = &json_object_string_delete; jso->_to_json_string = &json_object_string_to_json_string; - jso->o.c_string.str = malloc(len); + jso->o.c_string.str = (char*)malloc(len); memcpy(jso->o.c_string.str, (void *)s, len); jso->o.c_string.len = len; return jso; diff --git a/json_tokener.c b/json_tokener.c index 1c82484..47768f4 100644 --- a/json_tokener.c +++ b/json_tokener.c @@ -31,6 +31,13 @@ #include "json_tokener.h" #include "json_util.h" +#if !HAVE_STRDUP && defined(_MSC_VER) + /* MSC has the version as _strdup */ +# define strdup _strdup +#elif !HAVE_STRDUP +# error You do not have strdup on your system. +#endif /* HAVE_STRDUP */ + #if !HAVE_STRNCASECMP && defined(_MSC_VER) /* MSC has the version as _strnicmp */ # define strncasecmp _strnicmp @@ -38,7 +45,6 @@ # error You do not have strncasecmp on your system. #endif /* HAVE_STRNCASECMP */ - static const char* json_null_str = "null"; static const char* json_true_str = "true"; static const char* json_false_str = "false"; diff --git a/json_util.c b/json_util.c index e551d2d..03fb24b 100644 --- a/json_util.c +++ b/json_util.c @@ -20,19 +20,19 @@ #include #include -#if HAVE_SYS_TYPES_H +#ifdef HAVE_SYS_TYPES_H #include #endif /* HAVE_SYS_TYPES_H */ -#if HAVE_SYS_STAT_H +#ifdef HAVE_SYS_STAT_H #include #endif /* HAVE_SYS_STAT_H */ -#if HAVE_FCNTL_H +#ifdef HAVE_FCNTL_H #include #endif /* HAVE_FCNTL_H */ -#if HAVE_UNISTD_H +#ifdef HAVE_UNISTD_H # include #endif /* HAVE_UNISTD_H */ @@ -42,10 +42,16 @@ # include #endif /* defined(WIN32) */ -#if !HAVE_OPEN && defined(WIN32) +#if !defined(HAVE_OPEN) && defined(WIN32) # define open _open #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 "bits.h" #include "debug.h" @@ -204,7 +210,7 @@ int json_parse_int64(const char *buf, int64_t *retval) return 0; } -#if HAVE_REALLOC == 0 +#ifndef HAVE_REALLOC void* rpl_realloc(void* p, size_t n) { if (n == 0) diff --git a/printbuf.c b/printbuf.c index b951c7b..9d56522 100644 --- a/printbuf.c +++ b/printbuf.c @@ -19,7 +19,7 @@ #include #include -#if HAVE_STDARG_H +#ifdef HAVE_STDARG_H # include #else /* !HAVE_STDARG_H */ # error Not enough var arg support! @@ -108,13 +108,13 @@ int printbuf_memset(struct printbuf *pb, int offset, int charvalue, int len) return 0; } -#if !HAVE_VSNPRINTF && defined(_MSC_VER) +#if !defined(HAVE_VSNPRINTF) && defined(_MSC_VER) # define vsnprintf _vsnprintf -#elif !HAVE_VSNPRINTF /* !HAVE_VSNPRINTF */ +#elif !defined(HAVE_VSNPRINTF) /* !HAVE_VSNPRINTF */ # error Need vsnprintf! #endif /* !HAVE_VSNPRINTF && defined(WIN32) */ -#if !HAVE_VASPRINTF +#if !defined(HAVE_VASPRINTF) /* CAW: compliant version of vasprintf */ static int vasprintf(char **buf, const char *fmt, va_list ap) { diff --git a/tests/parse_flags.c b/tests/parse_flags.c index fafabc8..e33ffee 100644 --- a/tests/parse_flags.c +++ b/tests/parse_flags.c @@ -1,9 +1,17 @@ +#include "config.h" + #include #include #include "json.h" #include "parse_flags.h" +#if !defined(HAVE_STRCASECMP) && defined(_MSC_VER) +# define strcasecmp _stricmp +#elif !defined(HAVE_STRCASECMP) +# error You do not have strcasecmp on your system. +#endif /* HAVE_STRNCASECMP */ + static struct { const char *arg; int flag; diff --git a/tests/test1.c b/tests/test1.c index 9802eb1..87d7ea4 100644 --- a/tests/test1.c +++ b/tests/test1.c @@ -12,8 +12,8 @@ static int sort_fn (const void *j1, const void *j2) json_object * const *jso1, * const *jso2; int i1, i2; - jso1 = j1; - jso2 = j2; + jso1 = (json_object* const*)j1; + jso2 = (json_object* const*)j2; if (!*jso1 && !*jso2) { return 0; }