cdb_find(3)
π NAME π
okay so bestie, welcome to cdb_find β the function that goes and looks up a key in a constant database. that's the whole vibe. π
this one lives in the Library Functions Manual, section 3, and honestly? it ate. β¨
πΈ SYNTAX πΈ
first, you gotta pull in the headers like the little icons they are:
#include <libowfat/cdb.h>
#include <libowfat/uint32.h>
and here are the four function besties you're working with:
int cdb_find(struct cdb *c, char *key, size_t keylen);
int cdb_datalen(struct cdb *c);
int cdb_datapos(struct cdb *c);
int cdb_findnext(struct cdb *c, char *key, size_t keylen);
π DESCRIPTION π
so cdb_find looks for key, periodt. here's the tea on what it hands back:
- if
cdb_findreturns0, the database does not contain that key. so likeβ¦ stop. that's it. π - if
cdb_findreturns-1, there was a read error β abort. no cap, something went wrong. π
cdb_datalen returns the length of the data associated with the key. use it to allocate a pointer p with enough space to hold the data. like, you need a spot big enough to put the data in, and this tells you how big. π
cdb_datapos returns the position of the data inside the file. use it as the argument to cdb_read to retrieve the data. that's the where, and cdb_read is the how. π¦
alsooo β heads up β there may be several records under a single key. not just one. so if you wanna keep going, use cdb_findnext to find the next record under this key. it's giving "there's more where that came from." π₯
β¨ EXAMPLE β¨
here's the little snippet, copied exactly because we do not touch the code, bestie:
static struct c;
if (cdb_find(&c,key,strlen(key)>0) {
char *buf=alloca(cdb_datalen(&c));
cdb_read(&c,buf,cdb_datalen(&c),cdb_datapos(&c));
write(1,buf,cdb_datalen(&c));
}
not me double-checking that strlen(key)>0 is literally in there. it is. leave it. π«Ά
π SEE ALSO π
go give these icons a read too, iykyk:
and that's the whole page, bestie!! π you just read cdb_find(3) in all its glory β same page name, top to bottom, no notes. slay, go look up some keys. πβπ π§
π¦ where this page comes from
- alpine 3.24: libowfat-doc 0.34-r0 Β· GPL-2.0-only
- nixos 26.05: libowfat 0.34
- nixpkgs unstable: libowfat 0.34
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- ubuntu resolute: libowfat-dev 0.34-2 Β· GPL-2.0-only
- ubuntu stonking: libowfat-dev 0.34-2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms