Commit 5bc740e5 authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

added compatability for libjansson 2.9

parent de23031a
......@@ -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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment