You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB
Groff

.TH cdb_find 3
.SH NAME
cdb_find \- look up a key in a constant database
.SH SYNTAX
.B #include <libowfat/cdb.h>
.br
.B #include <libowfat/uint32.h>
int cdb_find(struct cdb *\fIc\fR, char *\fIkey\fR, size_t \fIkeylen\fR);
.br
int cdb_datalen(struct cdb *\fIc\fR);
.br
int cdb_datapos(struct cdb *\fIc\fR);
.br
int cdb_findnext(struct cdb *\fIc\fR, char *\fIkey\fR, size_t \fIkeylen\fR);
.SH DESCRIPTION
\fBcdb_find\fR looks for \fIkey\fR. If cdb_find returns 0, the database
does not contain that key; stop. If cdb_find returns -1, there was a
read error; abort.
\fBcdb_datalen\fR returns the length of the data associated with the
\fIkey\fR. Use it to allocate a pointer \fIp\fR with enough space to
hold the data.
\fBcdb_datapos\fR 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
\fBcdb_findnext\fR to find the next record under this key.
.SH 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));
.br
}
.SH "SEE ALSO"
cdb_read(3), cdb_init(3), cdb_free(3), cdbmake(1)