Browse Source

small man page updates and add a cdbget test

master
Felix von Leitner 15 years ago
parent
commit
5619ba06f2
  1. 2
      cdb/cdb_find.3
  2. 4
      cdb/cdb_read.3
  3. 31
      test/cdbget2.c

2
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));

4
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)

31
test/cdbget2.c

@ -0,0 +1,31 @@
#include <cdb.h>
#include <buffer.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errmsg.h>
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);
}
Loading…
Cancel
Save