From aaba8c1080533133329086e47f4f45981dfdd1ee Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Wed, 26 Oct 2016 10:37:50 +0300 Subject: [PATCH] compat/strdup.h: move common compat check for strdup() to own file Signed-off-by: Alexandru Ardelean --- CMakeLists.txt | 1 + Makefile.am | 1 + compat/strdup.h | 13 +++++++++++++ json-c.vcproj | 3 +++ json-c.vcxproj | 3 ++- json-c.vcxproj.filters | 5 ++++- json_object.c | 8 +------- json_tokener.c | 8 +------- 8 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 compat/strdup.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 5015708..39ffe24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ endif() include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) set(JSON_C_HEADERS + ./compat/strdup.h ./json.h ${CMAKE_CURRENT_BINARY_DIR}/include/config.h ./json_config.h diff --git a/Makefile.am b/Makefile.am index a5d126b..8f7af38 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,6 +18,7 @@ libjson_cincludedir = $(includedir)/json-c libjson_cinclude_HEADERS = \ arraylist.h \ bits.h \ + compat/strdup.h \ debug.h \ json.h \ json_c_version.h \ diff --git a/compat/strdup.h b/compat/strdup.h new file mode 100644 index 0000000..6b1a34c --- /dev/null +++ b/compat/strdup.h @@ -0,0 +1,13 @@ +#ifndef __STRDUP_H_COMPAT__ +#define __STRDUP_H_COMPAT__ + +#include "../config.h" + +#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 */ + +#endif /* __STRDUP_H_COMPAT__ */ diff --git a/json-c.vcproj b/json-c.vcproj index fcda288..184aa83 100644 --- a/json-c.vcproj +++ b/json-c.vcproj @@ -131,6 +131,9 @@ copy json_config.h.win32 json_config.h"/> + + diff --git a/json-c.vcxproj b/json-c.vcxproj index c39ef7e..d0f1e98 100644 --- a/json-c.vcxproj +++ b/json-c.vcxproj @@ -141,6 +141,7 @@ copy json_config.h.win32 json_config.h + @@ -162,4 +163,4 @@ copy json_config.h.win32 json_config.h - \ No newline at end of file + diff --git a/json-c.vcxproj.filters b/json-c.vcxproj.filters index 63b6fb1..7861064 100644 --- a/json-c.vcxproj.filters +++ b/json-c.vcxproj.filters @@ -47,6 +47,9 @@ Header Files + + Header Files + Header Files @@ -87,4 +90,4 @@ - \ No newline at end of file + diff --git a/json_object.c b/json_object.c index 8a70b5d..17fdd34 100644 --- a/json_object.c +++ b/json_object.c @@ -29,13 +29,7 @@ #include "json_object_private.h" #include "json_util.h" #include "math_compat.h" - -#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 */ +#include "compat/strdup.h" #if !defined(HAVE_SNPRINTF) && defined(_MSC_VER) /* MSC has the version as _snprintf */ diff --git a/json_tokener.c b/json_tokener.c index 65652f4..4521ef9 100644 --- a/json_tokener.c +++ b/json_tokener.c @@ -31,6 +31,7 @@ #include "json_object.h" #include "json_tokener.h" #include "json_util.h" +#include "compat/strdup.h" #ifdef HAVE_LOCALE_H #include @@ -41,13 +42,6 @@ #define jt_hexdigit(x) (((x) <= '9') ? (x) - '0' : ((x) & 7) + 9) -#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 -- 2.49.0