CBT(3X) CBT(3X) NAME bopen, bclose, bseek, bfirst, bkey, breclen, bread, bdelete, bwrite - compressed B-tree subroutines SYNOPSIS #include <cbt.h> bfile *bopen(name, typ) char *name; void bclose(b) bfile *b; bseek(b, key) bfile *b; mbuf key; bfirst(b) bfile *b; mbuf bkey(b) bfile *b; breclen(b) bfile *b; bread(b, key, val) bfile *b; mbuf *key, *val; bdelete(b, key) bfile *b; mbuf key; bwrite(b, key, val) bfile *b; mbuf key, val; DESCRIPTION These functions manipulate files of key/value records. Such files are created by cbt creat; see cbt(1). To load the functions use the ld(1) option -lcbt. The records occur sorted (increasing lexicographical order) by their keys, which must be distinct. Both keys and values are arrays of characters accessed through the structure typedef struct { char *mdata; address of data bytes short mlen; number of data bytes } mbuf; Bopen attempts to open a named B-tree, and if successful establishes a read pointer pointing to the beginning of the file and returns a pointer to be used in calling the other routines. Typ is 0 for read-only or 2 for read-write. Bopen returns a descriptor that identifies the file to the other functions. Bclose closes a B-tree. Bseek positions the read pointer of the file to the record whose key is the first not less than key. The routine returns 1 if key is in the file, EOF if key is greater than CBT(3X) CBT(3X) any key in the file, and 0 otherwise. Bfirst sets the read pointer to the beginning of the file. It has the same error return as bseek. Bkey returns the current key. The element mdata of the returned structure is 0 on errors, otherwise it points to a static buffer. Breclen returns the length of the value part of the current record. Bread reads the value at the read pointer into the space pointed to by val->mdata, places its length in `val->mlen', and advances the read pointer to the record with the next greater key. If key is not 0 the key of the record is read into the space pointed to by key->mdata and its length is placed in key->mlen. Bread returns 0 if successful. Bdelete removes the record with the given key, returning 1 if the record was found, -1 if there was an error, and 0 otherwise, The read pointer is left undefined. Bwrite writes the given value with the given key. An exist- ing record with that key will be replaced. The read pointer is left undefined. FILES SEE ALSO cbt(1), dbm(3) DIAGNOSTICS Routines which return pointers return 0 on errors, routines which return integers return -1. BUGS The length of any key is limited to 255. The mbuf arguments are passed inconsistently to the rou- tines, sometimes by value and sometimes by reference. Cbt files are not directly portable between big-endian and little-endian machines.