summaryrefslogtreecommitdiff
path: root/src/libstddjb/cdbmake_add.c
blob: f7fd096a18531e6fff7557b8c9234a193eaa8bf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* ISC license. */

#include <skalibs/uint32.h>
#include <skalibs/diuint32.h>
#include <skalibs/buffer.h>
#include <skalibs/genalloc.h>
#include <skalibs/cdbmake.h>
#include "cdb-internal.h"
#include "cdbmake-internal.h"

int cdbmake_add (cdbmaker *c, char const *key, uint32_t keylen, char const *data, uint32_t datalen)
{
  if (!cdbmake_addbegin(c, keylen, datalen)
   || buffer_put(&c->b, key, keylen) < keylen
   || buffer_put(&c->b, data, datalen) < datalen
   || !cdbmake_addend(c, keylen, datalen, cdb_hash(key, keylen)))
  {
    genalloc_free(diuint32, &c->hplist) ;
    return 0 ;
  }
  return 1 ;
}