skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

cdbmake_addbeginend.c (680B)


      1 /* ISC license. */
      2 
      3 #include <stdint.h>
      4 #include <errno.h>
      5 
      6 #include <skalibs/uint32.h>
      7 #include <skalibs/diuint32.h>
      8 #include <skalibs/buffer.h>
      9 #include <skalibs/genalloc.h>
     10 #include "cdbmake-internal.h"
     11 
     12 int cdbmake_addend (cdbmaker *c, uint32_t keylen, uint32_t datalen, uint32_t h)
     13 {
     14   diuint32 blah = { .left = h, .right = c->pos } ;
     15   return genalloc_append(diuint32, &c->hplist, &blah) && cdbmake_posplus(c, 8) && cdbmake_posplus(c, keylen) && cdbmake_posplus(c, datalen) ;
     16 }
     17 
     18 int cdbmake_addbegin (cdbmaker *c, uint32_t keylen, uint32_t datalen)
     19 {
     20   char buf[8] ;
     21   uint32_pack(buf, keylen) ;
     22   uint32_pack(buf + 4, datalen) ;
     23   return buffer_put(&c->b, buf, 8) == 8 ;
     24 }