qlibs:cdbmake(3)

πŸ“¦ version 31, in alpine 3.24

okay so bestie, you found qlibs:cdbmake(3), and it lives in the Library Functions Manual β€” it’s constant-database time, and we’re gonna be so normal about it πŸ’…βœ¨

πŸŽ€ NAME πŸŽ€

cdmake β€” generate and fill a constant database. That’s the name on the tin, fr fr.

✨ SYNTAX ✨

First, pull in the header exactly like this:

       #include "cdmake.h"

Then the three calls, copied exactly:

       int cdb_make_start(struct cdb *c,int fd);
       int cdb_make_add(struct cdb *c,char *key,unsigned int keylen,
                        char *data,unsigend int datalen);
       int cdb_make_finish(struct cdb *c);

πŸ’– DESCRIPTION πŸ’–

cdb_make_start generates and intitialises a brand-new cdb named c, and makes it available through file descriptor fd. New database, who dis 🫢

cdb_make_add adds entries using the file descriptor fd given as key with length keylen into the cdb, returning the hashed values data with length datalen.

cdb_make_finish finalises the data structure provided as fd. Wrap it up, bestie πŸŽ€

🌈 RETURN CODES 🌈

Usually, the cdb_make_* routines give you a return code of 0 for successful operations, and -1 if anything is going wrong. Simple as that, no cap 😭✨

πŸ¦‹ EXAMPLE πŸ¦‹

Here’s the whole vibe, code copied exactly:

       #include <cdbmake.h>

         int fd;
         stralloc data = {0};
         stralloc key = {0};

         struct cdb_make c;

         if (cdb_make_start(&c,fd) == -1) die_write();
         if (cdb_make_add(&c,key.s,key.len,data.s,data.len) == -1)
           die_write();
         if (cdb_make_finish(&c) == -1) die_write();
         if (fsync(fd) == -1) die_write();

πŸ“ SEE ALSO πŸ“

  • cdbread(3) β€” go read that next, bestie 🫢

β€” from the qlibs manual, page cdbmake(3), source/version sign-off qlibs:cdbmake(3) (the original footer doesn’t give a date, so I’m not inventing one, periodt πŸ’–βœ¨)

πŸ“¦ where this page comes from