diff --git a/include/villas/compat.h b/include/villas/compat.h new file mode 100644 index 000000000..3ad178c6c --- /dev/null +++ b/include/villas/compat.h @@ -0,0 +1,11 @@ +/** Compatability for different library versions. + * + * @author Steffen Vogel + * @copyright 2017, Institute for Automation of Complex Power Systems, EONERC + *********************************************************************************/ + +#include + +#if JANSSON_VERSION_HEX < 0x020A00 +size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags); +#endif \ No newline at end of file diff --git a/lib/Makefile.inc b/lib/Makefile.inc index b5bc29a30..0529873aa 100644 --- a/lib/Makefile.inc +++ b/lib/Makefile.inc @@ -10,6 +10,7 @@ LIB_SRCS = $(addprefix lib/nodes/, file.c cbuilder.c) \ log.c utils.c super_node.c hist.c timing.c pool.c \ list.c queue.c memory.c advio.c web.c api.c \ plugin.c node_type.c stats.c mapping.c sample_io.c\ + compat.c \ ) LIB_CFLAGS = $(CFLAGS) -fPIC diff --git a/lib/api.c b/lib/api.c index c63bfb5fe..ed8b27d66 100644 --- a/lib/api.c +++ b/lib/api.c @@ -11,26 +11,6 @@ #include "log.h" #include "config.h" -#if JANSSON_VERSION_HEX < 0x020A00 -size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags) -{ - char *str; - size_t len; - - str = json_dumps(json, flags); - if (!str) - return 0; - - len = strlen(str); // not \0 terminated - if (buffer && len <= size) - memcpy(buffer, str, len); - - free(str); - - return len; -} -#endif - static int api_parse_request(struct api_buffer *b, json_t **req) { json_error_t e; diff --git a/lib/compat.c b/lib/compat.c new file mode 100644 index 000000000..3d8413948 --- /dev/null +++ b/lib/compat.c @@ -0,0 +1,30 @@ +/** Compatability for different library versions. + * + * @author Steffen Vogel + * @copyright 2017, Institute for Automation of Complex Power Systems, EONERC + *********************************************************************************/ + +#include +#include + +#include "compat.h" + +#if JANSSON_VERSION_HEX < 0x020A00 +size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags) +{ + char *str; + size_t len; + + str = json_dumps(json, flags); + if (!str) + return 0; + + len = strlen(str); // not \0 terminated + if (buffer && len <= size) + memcpy(buffer, str, len); + + free(str); + + return len; +} +#endif \ No newline at end of file