1cdb_find(3) Library Functions Manual cdb_find(3)
2
3
4
6 cdb_find - look up a key in a constant database
7
9 #include <cdb.h>
10 #include <uint32.h>
11
12 int cdb_find(struct cdb *c,char *key,unsigned long int keylen);
13 int cdb_datalen(struct cdb *c);
14 int cdb_datapos(struct cdb *c);
15 int cdb_findnext(struct cdb *c,char *key,unsigned long int keylen);
16
17
19 cdb_find looks for key. If cdb_find returns 0, the database does not
20 contain that key; stop. If cdb_find returns -1, there was a read error;
21 abort.
22
23 cdb_datalen returns the length of the data associated with the key.
24 Use it to allocate a pointer p with enough space to hold the data.
25
26 cdb_datapos returns the position of the data inside the file. Use it
27 as argument to cdb_read to retrieve the data.
28
29 There may be several records under a single key. You can use cdb_find‐
30 next to find the next record under this key.
31
32
34 static struct c;
35
36 if (cdb_find(&c,key,strlen(key)>0) {
37 char *buf=alloca(cdb_datalen(&c));
38 cdb_read(&c,buf,cdb_datalen(&c),cdb_datapos(&c));
39 write(1,buf,cdb_datalen(&c));
40 }
41
43 cdb_read(3), cdb_init(3), cdb_free(3), cdbmake(1)
44
45
46
47 cdb_find(3)