1NDBM(3)                    Library Functions Manual                    NDBM(3)
2
3
4

NAME

6       dbm_open,  dbm_close,  dbm_fetch,  dbm_store, dbm_delete, dbm_firstkey,
7       dbm_nextkey, dbm_error, dbm_clearerr - data base subroutines
8

SYNOPSIS

10       #include <ndbm.h>
11
12       typedef struct {
13           char *dptr;
14           int dsize;
15       } datum;
16
17       DBM *dbm_open(file, flags, mode)
18           char *file;
19           int flags, mode;
20
21       void dbm_close(db)
22           DBM *db;
23
24       datum dbm_fetch(db, key)
25           DBM *db;
26           datum key;
27
28       int dbm_store(db, key, content, flags)
29           DBM *db;
30           datum key, content;
31           int flags;
32
33       int dbm_delete(db, key)
34           DBM *db;
35           datum key;
36
37       datum dbm_firstkey(db)
38           DBM *db;
39
40       datum dbm_nextkey(db)
41           DBM *db;
42
43       int dbm_error(db)
44           DBM *db;
45
46       int dbm_clearerr(db)
47           DBM *db;
48

DESCRIPTION

50       These functions maintain key/content pairs in a data base.   The  func‐
51       tions  will  handle  very  large  (a billion blocks) databases and will
52       access a keyed item in one or two file system accesses.   This  package
53       replaces the earlier dbm(3x) library, which managed only a single data‐
54       base.
55
56       Keys and contents are described by the datum typedef.  A  datum  speci‐
57       fies  a  string  of  dsize  bytes pointed to by dptr.  Arbitrary binary
58       data, as well as normal ASCII strings, are allowed.  The data  base  is
59       stored  in two files.  One file is a directory containing a bit map and
60       has `.dir' as its suffix.  The second file contains all  data  and  has
61       `.pag' as its suffix.
62
63       Before a database can be accessed, it must be opened by dbm_open.  This
64       will open and/or create the files file.dir and  file.pag  depending  on
65       the flags parameter (see open(2)).
66
67       Once  open,  the  data  stored under a key is accessed by dbm_fetch and
68       data is placed under a key by dbm_store.  The flags field can be either
69       DBM_INSERT  or  DBM_REPLACE.   DBM_INSERT  will only insert new entries
70       into the database and will not change an existing entry with  the  same
71       key.   DBM_REPLACE  will  replace  an existing entry if it has the same
72       key.  A key (and its associated contents) is deleted by dbm_delete.   A
73       linear  pass  through all keys in a database may be made, in an (appar‐
74       ently)  random  order,  by  use  of   dbm_firstkey   and   dbm_nextkey.
75       Dbm_firstkey  will  return  the first key in the database.  Dbm_nextkey
76       will return the next key in the database.  This code will traverse  the
77       data base:
78
79              for  (key  =  dbm_firstkey(db); key.dptr != NULL; key = dbm_nex‐
80              tkey(db))
81
82       Dbm_error returns non-zero when an error has occurred reading or  writ‐
83       ing the database.  Dbm_clearerr resets the error condition on the named
84       database.
85

DIAGNOSTICS

87       All functions that return an int indicate errors with negative  values.
88       A  zero  return  indicates  ok.   Routines that return a datum indicate
89       errors with a null (0) dptr.  If dbm_store called with a flags value of
90       DBM_INSERT finds an existing entry with the same key it returns 1.
91

BUGS

93       The  `.pag'  file will contain holes so that its apparent size is about
94       four times its actual content.  Older UNIX systems may create real file
95       blocks  for  these holes when touched.  These files cannot be copied by
96       normal means (cp, cat, tp, tar, ar) without filling in the holes.
97
98       Dptr pointers returned by these subroutines point into  static  storage
99       that is changed by subsequent calls.
100
101       The sum of the sizes of a key/content pair must not exceed the internal
102       block size (currently 4096 bytes).  Moreover all key/content pairs that
103       hash  together  must  fit  on a single block.  Dbm_store will return an
104       error in the event that a disk block fills with inseparable data.
105
106       Dbm_delete does not physically reclaim file  space,  although  it  does
107       make it available for reuse.
108
109       The  order of keys presented by dbm_firstkey and dbm_nextkey depends on
110       a hashing function, not on anything interesting.
111

SEE ALSO

113       dbm(3X)
114
115
116
1174.3 Berkeley Distribution        May 20, 1986                          NDBM(3)
Impressum