refer to ndbm
[unix-history] / usr / src / old / libndbm / dbm.3
CommitLineData
9058e83d
KM
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
4d4690e6 5.\" @(#)dbm.3 6.3 (Berkeley) %G%
9058e83d 6.\"
1a6873c6 7.TH DBM 3X ""
9058e83d
KM
8.UC 4
9.SH NAME
10dbminit, fetch, store, delete, firstkey, nextkey \- data base subroutines
11.SH SYNOPSIS
12.nf
13.PP
4fb1c171
DS
14.B "#include <dbm.h>"
15.PP
9058e83d
KM
16.B typedef struct {
17.B " char *dptr;"
18.B " int dsize;"
19.B } datum;
20.PP
21.B dbminit(file)
22.B char *file;
23.PP
24.B datum fetch(key)
25.B datum key;
26.PP
27.B store(key, content)
28.B datum key, content;
29.PP
30.B delete(key)
31.B datum key;
32.PP
33.B datum firstkey()
34.PP
35.B datum nextkey(key)
36.B datum key;
37.SH DESCRIPTION
4d4690e6
MK
38.ft B
39Note: the dbm library has been superceded by ndbm(3),
40and is now implemented using ndbm.
41.ft R
7f5314cf
KM
42These functions maintain key/content pairs in a data base.
43The functions will handle very large (a billion blocks)
44databases and will access a keyed item in one or two file system accesses.
9058e83d
KM
45The functions are obtained with the loader option
46.BR \-ldbm .
47.PP
48.IR Key s
49and
50.IR content s
7f5314cf 51are described by the
9058e83d 52.I datum
7f5314cf 53typedef. A
9058e83d
KM
54.I datum
55specifies a string of
56.I dsize
57bytes pointed to by
58.I dptr.
7f5314cf 59Arbitrary binary data, as well as normal ASCII strings, are allowed.
9058e83d 60The data base is stored in two files.
7f5314cf
KM
61One file is a directory containing a bit map and has `.dir' as its suffix.
62The second file contains all data and has `.pag' as its suffix.
9058e83d 63.PP
7f5314cf 64Before a database can be accessed, it must be opened by
9058e83d 65.I dbminit.
7f5314cf 66At the time of this call, the files
9058e83d
KM
67.IB file .dir
68and
69.IB file .pag
70must exist.
7f5314cf 71(An empty database is created by creating zero-length
9058e83d
KM
72`.dir' and `.pag' files.)
73.PP
7f5314cf 74Once open, the data stored under a key is accessed by
9058e83d 75.I fetch
7f5314cf 76and data is placed under a key by
9058e83d 77.IR store .
7f5314cf 78A key (and its associated contents) is deleted by
9058e83d 79.IR delete .
7f5314cf
KM
80A linear pass through all keys in a database may be made,
81in an (apparently) random order, by use of
9058e83d
KM
82.I firstkey
83and
84.IR nextkey .
85.I Firstkey
7f5314cf 86will return the first key in the database. With any key
9058e83d
KM
87.I nextkey
88will return the next key in the database.
89This code will traverse the data base:
90.IP
91.B for
92(key = firstkey(); key.dptr != NULL; key = nextkey(key))
93.SH DIAGNOSTICS
94All functions that return an
95.I int
7f5314cf 96indicate errors with negative values. A zero return indicates ok.
9058e83d
KM
97Routines that return a
98.I datum
99indicate errors with a null (0)
100.I dptr.
4d4690e6
MK
101.SH SEE ALSO
102ndbm(3)
9058e83d 103.SH BUGS
7f5314cf
KM
104The `.pag' file will contain holes so that its apparent size is about
105four times its actual content. Older UNIX systems may create real
106file blocks for these holes when touched. These files cannot be copied
107by normal means (cp, cat, tp, tar, ar) without filling in the holes.
9058e83d
KM
108.PP
109.I Dptr
7f5314cf 110pointers returned by these subroutines point into static storage
9058e83d
KM
111that is changed by subsequent calls.
112.PP
7f5314cf
KM
113The sum of the sizes of a key/content pair must not exceed
114the internal block size (currently 1024 bytes).
115Moreover all key/content pairs that hash together must fit on a single block.
9058e83d 116.I Store
7f5314cf 117will return an error in the event that a disk block fills with inseparable data.
9058e83d
KM
118.PP
119.I Delete
120does not physically reclaim file space,
121although it does make it available for reuse.
122.PP
123The order of keys presented by
124.I firstkey
125and
126.I nextkey
7f5314cf 127depends on a hashing function, not on anything interesting.