---
name: "cdb_find"
section: "3"
platform: "linux"
package: "libowfat-dev"
version: "0.32-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/cdb_find"
---

# cdb\_find(3)

look up a key in a constant database

## NAME

cdb\_find - look up a key in a constant database

## SYNTAX

**#include \<libowfat/cdb.h\>**\
 **#include \<libowfat/uint32.h\>**

int cdb\_find(struct cdb \**c*,char \**key*,unsigned long int *keylen*);\
 int cdb\_datalen(struct cdb \**c*);\
 int cdb\_datapos(struct cdb \**c*);\
 int cdb\_findnext(struct cdb \**c*,char \**key*,unsigned long int *keylen*);

## DESCRIPTION

**cdb\_find** looks for *key*. If cdb\_find returns 0, the database does not contain that key; stop. If cdb\_find returns -1, there was a read error; abort.

**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.

**cdb\_datapos** returns the position of the data inside the file.  Use it as argument to cdb\_read to retrieve the data.

There may be several records under a single key. You can use **cdb\_findnext** to find the next record under this key.

## EXAMPLE

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));\
 }

## SEE ALSO

[cdb\_read(3)](/cdb_read/3.md), [cdb\_init(3)](/cdb_init/3.md), [cdb\_free(3)](/cdb_free/3.md), [cdbmake(1)](/cdbmake/1.md)
