The
ndbm facility provides access to hash database files.
Two data types are fundamental to the
ndbm facility.
DBM serves as a handle to a database. It is an opaque type.
The other data type is
datum, which is a structure type which includes the following members:
A
datum is thus given by
dptr pointing at an object of
dsize bytes in length.
The
dbm_open() function opens a database. The
file argument is the pathname which the actual database file pathname is based on. This implementation uses a single file with the suffix
.db appended to
file. The
open_flags argument has the same meaning as the
flags argument to
open(2) except that when opening a database for write-only access the file is opened for read/write access, and the
O_APPEND flag must not be specified. The
file_mode argument has the same meaning as the
mode argument to
open(2).
For the following functions, the
db argument is a handle previously returned by a call to
dbm_open().
The
dbm_close() function closes a database.
The
dbm_fetch() function retrieves a record from the database. The
key argument is a
datum that identifies the record to be fetched.
The
dbm_store() function stores a record into the database. The
key argument is a
datum that identifies the record to be stored. The
content argument is a
datum that specifies the value of the record to be stored. The
store_mode argument specifies the behavior of
dbm_store() if a record matching
key is already present in the database,
db.
store_mode must be one of the following:
DBM_INSERT
If a record matching key is already present, it is left unchanged.
DBM_REPLACE
If a record matching key is already present, its value is replaced by content.
If no record matching
key is present, a new record is inserted regardless of
store_mode.
The
dbm_delete() function deletes a record from the database. The
key argument is a
datum that identifies the record to be deleted.
The
dbm_firstkey() function returns the first key in the database.
The
dbm_nextkey() function returns the next key in the database. In order to be meaningful, it must be preceded by a call to
dbm_firstkey().
The
dbm_error() function returns the error indicator of the database.
The
dbm_clearerr() function clears the error indicator of the database.
The
dbm_dirfno() function returns the file descriptor of the underlying database file.