1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

added compat.c for adding compatibility with older library versions

This commit is contained in:
Steffen Vogel 2017-04-03 09:02:18 +02:00
parent 6d3ee5baac
commit 047ddde0c4
4 changed files with 42 additions and 20 deletions

11
include/villas/compat.h Normal file
View file

@ -0,0 +1,11 @@
/** Compatability for different library versions.
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
*********************************************************************************/
#include <jansson.h>
#if JANSSON_VERSION_HEX < 0x020A00
size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags);
#endif

View file

@ -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

View file

@ -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;

30
lib/compat.c Normal file
View file

@ -0,0 +1,30 @@
/** Compatability for different library versions.
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
*********************************************************************************/
#include <string.h>
#include <jansson.h>
#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