1DBM(3X)                                                                DBM(3X)
2
3
4

NAME

6       dbminit,  fetch,  store,  delete, firstkey, nextkey - data base subrou‐
7       tines
8

SYNOPSIS

10       #include <dbm.h>
11
12       typedef struct {
13            char *dptr;
14            int dsize;
15       } datum;
16
17       dbminit(file)
18       char *file;
19
20       datum fetch(key)
21       datum key;
22
23       store(key, content)
24       datum key, content;
25
26       delete(key)
27       datum key;
28
29       datum firstkey()
30
31       datum nextkey(key)
32       datum key;
33

DESCRIPTION

35       Note: the dbm library has been superceded by ndbm(3), and is now imple‐
36       mented  using  ndbm.   These  functions maintain key/content pairs in a
37       data base.  The functions will handle very  large  (a  billion  blocks)
38       databases  and  will  access  a  keyed  item  in one or two file system
39       accesses.  The functions are obtained with the loader option -ldbm.
40
41       Keys and contents are described by the datum typedef.  A  datum  speci‐
42       fies  a  string  of  dsize  bytes pointed to by dptr.  Arbitrary binary
43       data, as well as normal ASCII strings, are allowed.  The data  base  is
44       stored  in two files.  One file is a directory containing a bit map and
45       has `.dir' as its suffix.  The second file contains all  data  and  has
46       `.pag' as its suffix.
47
48       Before  a  database  can be accessed, it must be opened by dbminit.  At
49       the time of this call, the files file.dir and file.pag must exist.  (An
50       empty  database  is  created  by creating zero-length `.dir' and `.pag'
51       files.)
52
53       Once open, the data stored under a key is accessed by fetch and data is
54       placed  under  a  key by store.  A key (and its associated contents) is
55       deleted by delete.  A linear pass through all keys in a database may be
56       made,  in an (apparently) random order, by use of firstkey and nextkey.
57       Firstkey will return the first key in the database.  With any key  nex‐
58       tkey will return the next key in the database.  This code will traverse
59       the data base:
60
61              for (key = firstkey(); key.dptr != NULL; key = nextkey(key))
62

DIAGNOSTICS

64       All functions that return an int indicate errors with negative  values.
65       A  zero  return  indicates  ok.   Routines that return a datum indicate
66       errors with a null (0) dptr.
67

SEE ALSO

69       ndbm(3)
70

BUGS

72       The `.pag' file will contain holes so that its apparent size  is  about
73       four times its actual content.  Older UNIX systems may create real file
74       blocks for these holes when touched.  These files cannot be  copied  by
75       normal means (cp, cat, tp, tar, ar) without filling in the holes.
76
77       Dptr  pointers  returned by these subroutines point into static storage
78       that is changed by subsequent calls.
79
80       The sum of the sizes of a key/content pair must not exceed the internal
81       block size (currently 1024 bytes).  Moreover all key/content pairs that
82       hash together must fit on a single block.  Store will return  an  error
83       in the event that a disk block fills with inseparable data.
84
85       Delete does not physically reclaim file space, although it does make it
86       available for reuse.
87
88       The order of keys presented by firstkey and nextkey depends on a  hash‐
89       ing function, not on anything interesting.
90
91
92
934th Berkeley Distribution        May 12, 1986                          DBM(3X)
Impressum