NAME
bread, bwrite, bopen, bclose, bseek, bkey, bdelete, bfirst, bflush, breclen cbt(3)

SYNOPSIS
typedef struct { char *mdata; unsigned short mlen; } mbuf;
#include cbt.h
bfile *bopen(file, type) char *file;
bseek(bf, key) bfile *bf; mbuf key;
bfirst(bf) bfile *bf;
bclose(bf) bfile *bf;
breclen(bf) bfile *bf;
bread(bf, key, value) bfile *bf; mbuf *key, *value;
bdelete(bf, key) bfile *bf; mbuf key;
bflush(bf) bfile *bf;

DESCRIPTION
These subroutines are the C interface to B-tree files. Load them using -lcbt. The include file contains the definition of mbuf. B-trees may be shared by multiple readers and a single writer, since the effect of a writer's changes are not seen until the root of the tree is written back. Keys can be no longer than 255 bytes. The routines communicate by means of a bfile pointer returned by bopen. A B-tree named file corresponds to two files, file.T and (if the file is not an index) file.F. The type parameter to bopen should be either 0 or 2, as in open (2).
bclose closes a B-tree and (if necessary) rewrites its root.
bflush writes the root without closing the B-tree.

The subroutines keep track of a current position in each open B-tree. When the B-tree is opened the current position is just before the first key. Calling bfirst has the same effect. bseek makes the current position just before the key and returns FOUND, if the key exists in the file, or it makes the current position just before the next largest key and returns NOTFOUND, or, if there is no larger key in the file it returns EOF. bread returns the key and value at the current position, and advances the current position. Note that the arguments to bread are all pointers. If either key or value are NULL, the corresponding argument is not returned. bread stores its results in the buffers given in the arguments, and sets the lengths of the results in the arguments. breclen returns the length of the value which will be returned by the next call to bread.