diff --git a/cdb/cdb_find.3 b/cdb/cdb_find.3 index 34eb41d..f0b6af7 100644 --- a/cdb/cdb_find.3 +++ b/cdb/cdb_find.3 @@ -30,7 +30,7 @@ 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 cdb; +static struct c; if (cdb_find(&c,key,strlen(key)>0) { char *buf=alloca(cdb_datalen(&c)); diff --git a/cdb/cdb_read.3 b/cdb/cdb_read.3 index ce7646b..9db0bb1 100644 --- a/cdb/cdb_read.3 +++ b/cdb/cdb_read.3 @@ -16,5 +16,9 @@ int cdb_read(struct cdb *\fIc\fR,char *\fIbuf\fR,unsigned long int \fIlen\fR,uin \fIbuf\fR needs to point to a memory region large enough to hold \fIlen\fR bytes. +.SH "RETURN VALUE" +\fBcdb_read\fR returns 0 if everything went well, or -1 on error +(setting \fIerrno\fR appropriately. + .SH "SEE ALSO" cdb_find(3), cdb_init(3), cdb_free(3), cdbmake(1) diff --git a/test/cdbget2.c b/test/cdbget2.c new file mode 100644 index 0000000..614638e --- /dev/null +++ b/test/cdbget2.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc,char* argv[]) { + int fd; + static struct cdb c; + errmsg_iam("cdbget"); + if (argc<3) + die(1,"usage: cdbget data.cdb key"); + fd=open(argv[1],O_RDONLY); + if (fd==-1) + diesys(1,"open"); + cdb_init(&c,fd); + if (cdb_find(&c,argv[2],strlen(argv[2]))>0) { + do { + char* x=malloc(cdb_datalen(&c)); + if (!x) + die(1,"out of memory"); + if (cdb_read(&c,x,cdb_datalen(&c),cdb_datapos(&c))==-1) + diesys(1,"cdb_read"); + buffer_put(buffer_1,x,cdb_datalen(&c)); + buffer_put(buffer_1,"\n",1); + free(x); + } while (cdb_findnext(&c,argv[2],strlen(argv[2]))>0); + } + buffer_flush(buffer_1); +}