diff options
Diffstat (limited to 'src/cache/conf.c')
-rw-r--r-- | src/cache/conf.c | 36 |
1 files changed, 36 insertions, 0 deletions
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 <errno.h> +#include <string.h> + +#include <skalibs/uint32.h> +#include <skalibs/cdb.h> + +#include "shibari-cache-internal.h" + +#include <skalibs/posixishard.h> + +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 ; +} |