From 0beff2477b55728603127f21a9df604b6fcf840c Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 3 Jul 2023 11:10:09 +0000 Subject: Refactor cdbmake, add cdbmake_addv, cdb_hashv Signed-off-by: Laurent Bercot --- src/libstddjb/cdbmake_addv.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/libstddjb/cdbmake_addv.c (limited to 'src/libstddjb/cdbmake_addv.c') diff --git a/src/libstddjb/cdbmake_addv.c b/src/libstddjb/cdbmake_addv.c new file mode 100644 index 0000000..d8719a4 --- /dev/null +++ b/src/libstddjb/cdbmake_addv.c @@ -0,0 +1,30 @@ +/* ISC license. */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include "cdb-internal.h" +#include "cdbmake-internal.h" + +int cdbmake_addv (cdbmaker *c, struct iovec const *kv, unsigned int kn, struct iovec const *dv, unsigned int dn) +{ + size_t keylen = siovec_len(kv, kn) ; + size_t datalen = siovec_len(dv, dn) ; + if (keylen > UINT32_MAX || datalen > UINT32_MAX) return (errno = EOVERFLOW, 0) ; + + if (!cdbmake_addbegin(c, keylen, datalen) + || buffer_putv(&c->b, kv, kn) < keylen + || buffer_putv(&c->b, dv, dn) < datalen + || !cdbmake_addend(c, keylen, datalen, cdb_hashv(kv, kn))) + { + genalloc_free(diuint32, &c->hplist) ; + return 0 ; + } + return 1 ; +} -- cgit v1.2.3