ndbm(3X)ndbm(3X)NAME
dbm_open, dbm_close, dbm_fetch, dbm_store, dbm_delete, dbm_firstkey,
dbm_nextkey, dbm_error, dbm_clearerr - database subroutines
SYNOPSISDESCRIPTION
These functions maintain key/content pairs in a database. They handle
very large (a billion blocks (block = 1024 bytes)) databases and can
access a keyed item in one or two file system accesses.
key and content parameters are described by the type. A specifies a
string of dsize bytes pointed to by dptr. Arbitrary binary data, as
well as normal ASCII strings, are allowed. The database is stored in
two files. One file is a directory containing a bit map of keys and
has as its suffix. The second file contains all data and has as its
suffix.
Before a database can be accessed, it must be opened by This will open
and/or create the files and depending on the flags parameter (see
open(2)).
Once open, the data stored under a key is accessed by and data is
placed under a key by The flags field can be either or can only insert
new entries into the database, and cannot change an existing entry hav‐
ing the same key. replaces an existing entry if it has the same key.
A key (and its associated contents) is deleted by A linear pass through
all keys in a database can be made in (apparently) random order by use
of and returns the first key in the database. returns the next key in
the database, The following code can be used to traverse the database:
returns non-zero when an error has occurred reading or writing the
database. resets the error condition on the named database.
DIAGNOSTICS
All functions that return an indicate errors with negative values and
success with zero. Functions that return a indicate errors with a null
dptr. If is called with a flags value of and finds an existing entry
with the same key, a value of is returned. If a call to results in an
internal block overflow, a value of −2 is returned.
WARNINGS
The ndbm functions provided in this library should not be confused in
any way with those of a general-purpose database management system.
These functions provide for multiple search keys per entry, they pro‐
tect against multi-user access (in other words they do not lock records
or files), and they provide the many other useful database functions
that are found in more robust database management systems. Creating
and updating databases by use of these functions is relatively slow
because of data copies that occur upon hash collisions. These func‐
tions for applications requiring fast lookup of relatively static
information that is to be indexed by a single key.
The pointer to data that is returned from these functions are not
aligned. This can cause problems if the block contains data that must
be aligned to a specific boundry. If the block contains data that must
be aligned, the block should be copied to an appropriately aligned
area.
The file will contain holes so that its apparent size is about four
times its actual content. Some older UNIX systems create real file
blocks for these holes when touched. These files cannot be copied by
normal means (such as cp(1), cat(1), tar(1), or ar(1)) without expan‐
sion.
dptr pointers returned by these subroutines point into static storage
that is changed by subsequent calls.
The sum of the sizes of a key/content pair must not exceed the internal
block size (currently 1024 bytes). Moreover, all key/content pairs
that hash together must fit on a single block. returns an error in the
event that a disk block fills with inseparable data.
does not physically reclaim file space, although it does make it avail‐
able for reuse.
The order of keys presented by and depends on a hashing function, not
on anything interesting.
A or during a pass through the keys by and may yield unexpected
results.
AUTHORndbm(3X) was developed by the University of California, Berkeley.
SEE ALSOdbm(3C), thread_safety(5).
ndbm(3X)