From 77942af25401d1bfb4d159898a278ef42fd36f7b Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 23 Mar 2022 19:52:14 +0100 Subject: build: add polyfills for older libjson-c versions The libjson-c versions commonly shipped by Debian and Ubuntu lack unsigned 64bit integer support and a number of extended API functions. Signed-off-by: Jo-Philipp Wich --- include/ucode/util.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'include') diff --git a/include/ucode/util.h b/include/ucode/util.h index 3203499..35c1e56 100644 --- a/include/ucode/util.h +++ b/include/ucode/util.h @@ -159,4 +159,30 @@ static inline struct printbuf *xprintbuf_new(void) { return pb; } + +/* json-c compat */ + +#ifndef HAVE_PARSE_END +static inline size_t json_tokener_get_parse_end(struct json_tokener *tok) { + return (size_t)tok->char_offset; +} +#endif + +#ifndef HAVE_ARRAY_EXT +static inline struct json_object *json_object_new_array_ext(int size) { + (void) size; + return json_object_new_array(); +} +#endif + +#ifndef HAVE_JSON_UINT64 +static inline struct json_object *json_object_new_uint64(uint64_t i) { + return json_object_new_int64((int64_t)i); +} + +static inline uint64_t json_object_get_uint64(const struct json_object *obj) { + return (uint64_t)json_object_get_int64(obj); +} +#endif + #endif /* UCODE_UTIL_H */ -- cgit v1.2.3