mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
added compatability for libjansson 2.9
This commit is contained in:
parent
0fe20489c7
commit
fb68c375e6
2 changed files with 34 additions and 0 deletions
|
@ -32,6 +32,9 @@ extern "C" {
|
|||
|
||||
#if JANSSON_VERSION_HEX < 0x020A00
|
||||
size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags);
|
||||
|
||||
int json_dumpfd(const json_t *json, int output, size_t flags);
|
||||
json_t *json_loadfd(int input, size_t flags, json_error_t *error);
|
||||
#endif
|
||||
|
||||
#if defined(LIBCONFIG_FOUND) && (LIBCONFIG_VER_MAJOR <= 1) && (LIBCONFIG_VER_MINOR < 5)
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <string.h>
|
||||
#include <jansson.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <villas/compat.h>
|
||||
|
||||
|
@ -43,4 +44,34 @@ size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags)
|
|||
|
||||
return len;
|
||||
}
|
||||
|
||||
static size_t json_loadfd_callback(void *buffer, size_t buflen, void *data)
|
||||
{
|
||||
int *fd = (int *) data;
|
||||
|
||||
return (size_t) read(*fd, buffer, buflen);
|
||||
}
|
||||
|
||||
json_t *json_loadfd(int input, size_t flags, json_error_t *error)
|
||||
{
|
||||
return json_load_callback(json_loadfd_callback, (void *) &input, flags, error);
|
||||
}
|
||||
|
||||
|
||||
static int json_dumpfd_callback(const char *buffer, size_t size, void *data)
|
||||
{
|
||||
#ifdef HAVE_UNISTD_H
|
||||
int *dest = (int *)data;
|
||||
|
||||
if (write(*dest, buffer, size) == (ssize_t)size)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int json_dumpfd(const json_t *json, int output, size_t flags)
|
||||
{
|
||||
return json_dump_callback(json, json_dumpfd_callback, (void *) &output, flags);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue