From d1c4602f80e395d1d6ab0453b8f0a6cc10aefadf Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Tue, 16 Jul 2024 01:51:04 +0000 Subject: Refactor dcache, add prep for shibari-cache Signed-off-by: Laurent Bercot --- src/cache/conf.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/cache/conf.c (limited to 'src/cache/conf.c') diff --git a/src/cache/conf.c b/src/cache/conf.c new file mode 100644 index 0000000..ea35646 --- /dev/null +++ b/src/cache/conf.c @@ -0,0 +1,36 @@ +/* ISC license. */ + +#include +#include + +#include +#include + +#include "shibari-cache-internal.h" + +#include + +int conf_getb (cdb const *c, char const *key, size_t keylen, cdb_data *data) +{ + if (keylen > 4096) return (errno = EINVAL, 0) ; + switch (cdb_find(c, data, key, keylen)) + { + case -1 : return (errno = EILSEQ, 0) ; + case 0 : return (errno = ENOENT, 0) ; + default : return 1 ; + } +} + +int conf_get (cdb const *c, char const *key, cdb_data *data) +{ + return conf_get(c, key, strlen(key), data) ; +} + +int conf_get_uint32 (cdb const *c, char const *key, uint32_t *value) +{ + cdb_data data ; + if (!conf_get(conf, key, &data)) return 0 ; + if (data.len != 4) return (errno = EPROTO, 0) ; + uint32_unpack_big(data.s, value) ; + return 1 ; +} -- cgit v1.3.1