DBM(3) BSD Library Functions Manual DBM(3)
NAME
dbmclearerr, dbmclose, dbmdelete, dbmdirfno, dbmerror, dbmfetch,
dbmfirstkey, dbmnextkey, dbmopen, dbmstore -- database access func-
tions
SYNOPSIS
##include <>
##include <>
DBM *
dbmopen(const char *base, int flags, int mode);
void
dbmclose(DBM *db);
int
dbmstore(DBM *db, datum key, datum data, int flags);
datum
dbmfetch(DBM *db, datum key);
int
dbmdelete(DBM *db, datum key);
datum
dbmfirstkey(DBM *db);
datum
dbmnextkey(DBM *db);
int
dbmerror(DBM *db);
int
dbmclearerr(DBM *db);
int
dbmdirfno(DBM *db);
DESCRIPTION
Database access functions. These functions are implemented using
dbopen(3) with a hash(3) database.
datum is declared in :
typedef struct {
char *dptr;
int dsize;
} datum;
The dbmopen(base, flags, mode) function opens or creates a database.
The base argument is the basename of the file containing the database;
the actual database has a .db suffix. I.e., if base is
"/home/me/mystuff" then the actual database is in the file
/home/me/mystuff.db. The flags and mode arguments are passed to open(2).
(ORDWR OCREAT) is a typical value for flags; 0660 is a typical value
for mode. OWRONLY is not allowed in flags. The pointer returned by
dbmopen() identifies the database and is the db argument to the other
functions. The dbmopen() function returns NUL and sets errno if there
were any errors.
The dbmclose(db) function closes the database. The dbmclose() function
normally returns zero.
The dbmstore(db, key, data, flags) function inserts or replaces an entry
in the database. The flags argument is either DBMINSERT or DBMREPLACE.
If flags is DBMINSERT and the database already contains an entry for
key, that entry is not replaced. Otherwise the entry is replaced or
inserted. The dbmstore() function normally returns zero but returns 1
if the entry could not be inserted (because flags is DBMINSERT, and an
entry with key already exists) or returns -1 and sets errno if there were
any errors.
The dbmfetch(db, key) function returns NUL or the data corresponding to
key.
The dbmdelete(db, key) function deletes the entry for key. The
dbmdelete() function normally returns zero but returns 1 if there was no
entry with key in the database or returns -1 and sets errno if there were
any errors.
The dbmfirstkey(db) function returns the first key in the database. The
dbmnextkey(db) function returns subsequent keys. The dbfirstkey()
function must be called before dbmnextkey(). The order in which keys
are returned is unspecified and may appear random. The dbmnextkey()
function returns NUL after all keys have been returned.
The dbmerror(db) function returns the errno value of the most recent
error. The dbmclearerr(db) function resets this value to 0 and returns
0.
The dbmdirfno(db) function returns the file descriptor to the database.
SEE ALSO
open(2), dbopen(3), hash(3)
STANDARDS
These functions (except dbmdirfno()) are included in the Version 2 of
the Single UNIX Specification (``SUSv2'').
BSD July 7, 1999 BSD
|