xref: /freebsd/lib/libc/db/man/dbm.3 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
1480e9923SNik Clayton.\" Copyright (c) 1999 Tim Singletary
2480e9923SNik Clayton.\" No copyright is claimed.
3480e9923SNik Clayton.\"
4480e9923SNik Clayton.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
5480e9923SNik Clayton.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
6480e9923SNik Clayton.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7480e9923SNik Clayton.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
8480e9923SNik Clayton.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
9480e9923SNik Clayton.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
10480e9923SNik Clayton.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
11480e9923SNik Clayton.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
12480e9923SNik Clayton.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
13480e9923SNik Clayton.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
14480e9923SNik Clayton.\" SUCH DAMAGE.
15480e9923SNik Clayton.\"
16*4b7f35dbSGordon Bergling.Dd April 2, 2022
1795cf33c5SRuslan Ermilov.Dt DBM 3
1895cf33c5SRuslan Ermilov.Os
19480e9923SNik Clayton.Sh NAME
2095cf33c5SRuslan Ermilov.Nm dbm_clearerr ,
2195cf33c5SRuslan Ermilov.Nm dbm_close ,
2295cf33c5SRuslan Ermilov.Nm dbm_delete ,
2395cf33c5SRuslan Ermilov.Nm dbm_dirfno ,
2495cf33c5SRuslan Ermilov.Nm dbm_error ,
2595cf33c5SRuslan Ermilov.Nm dbm_fetch ,
2695cf33c5SRuslan Ermilov.Nm dbm_firstkey ,
2795cf33c5SRuslan Ermilov.Nm dbm_nextkey ,
2895cf33c5SRuslan Ermilov.Nm dbm_open ,
29480e9923SNik Clayton.Nm dbm_store
30480e9923SNik Clayton.Nd database access functions
31480e9923SNik Clayton.Sh SYNOPSIS
3232eef9aeSRuslan Ermilov.In fcntl.h
3332eef9aeSRuslan Ermilov.In ndbm.h
34480e9923SNik Clayton.Ft DBM *
35de1d2695SEd Schouten.Fn dbm_open "const char *base" "int flags" "mode_t mode"
36480e9923SNik Clayton.Ft void
37480e9923SNik Clayton.Fn dbm_close "DBM *db"
38480e9923SNik Clayton.Ft int
39480e9923SNik Clayton.Fn dbm_store "DBM *db" "datum key" "datum data" "int flags"
40480e9923SNik Clayton.Ft datum
41480e9923SNik Clayton.Fn dbm_fetch "DBM *db" "datum key"
42480e9923SNik Clayton.Ft int
43480e9923SNik Clayton.Fn dbm_delete "DBM *db" "datum key"
44480e9923SNik Clayton.Ft datum
45480e9923SNik Clayton.Fn dbm_firstkey "DBM *db"
46480e9923SNik Clayton.Ft datum
47480e9923SNik Clayton.Fn dbm_nextkey "DBM *db"
48480e9923SNik Clayton.Ft int
49480e9923SNik Clayton.Fn dbm_error "DBM *db"
50480e9923SNik Clayton.Ft int
51480e9923SNik Clayton.Fn dbm_clearerr "DBM *db"
52480e9923SNik Clayton.Ft int
53480e9923SNik Clayton.Fn dbm_dirfno "DBM *db"
54480e9923SNik Clayton.Sh DESCRIPTION
55480e9923SNik ClaytonDatabase access functions.
56480e9923SNik ClaytonThese functions are implemented using
5795cf33c5SRuslan Ermilov.Xr dbopen 3
58480e9923SNik Claytonwith a
5995cf33c5SRuslan Ermilov.Xr hash 3
60480e9923SNik Claytondatabase.
6195cf33c5SRuslan Ermilov.Pp
6295cf33c5SRuslan Ermilov.Vt datum
63480e9923SNik Claytonis declared in
64fe08efe6SRuslan Ermilov.In ndbm.h :
65480e9923SNik Clayton.Bd -literal
66480e9923SNik Claytontypedef struct {
672fed5061SEd Schouten	void *dptr;
68480e9923SNik Clayton	int dsize;
69480e9923SNik Clayton} datum;
70480e9923SNik Clayton.Ed
7195cf33c5SRuslan Ermilov.Pp
721fae73b1SRuslan ErmilovThe
73480e9923SNik Clayton.Fn dbm_open base flags mode
741fae73b1SRuslan Ermilovfunction
75480e9923SNik Claytonopens or creates a database.
762efeeba5SRuslan ErmilovThe
7795cf33c5SRuslan Ermilov.Fa base
782efeeba5SRuslan Ermilovargument
7995cf33c5SRuslan Ermilovis the basename of the file containing
80480e9923SNik Claytonthe database; the actual database has a
8195cf33c5SRuslan Ermilov.Pa .db
8295cf33c5SRuslan Ermilovsuffix.
8395cf33c5SRuslan ErmilovI.e., if
84480e9923SNik Clayton.Fa base
85480e9923SNik Claytonis
8695cf33c5SRuslan Ermilov.Qq Li /home/me/mystuff
87480e9923SNik Claytonthen the actual database is in the file
8895cf33c5SRuslan Ermilov.Pa /home/me/mystuff.db .
892efeeba5SRuslan ErmilovThe
9095cf33c5SRuslan Ermilov.Fa flags
9195cf33c5SRuslan Ermilovand
9295cf33c5SRuslan Ermilov.Fa mode
932efeeba5SRuslan Ermilovarguments
9495cf33c5SRuslan Ermilovare passed to
9595cf33c5SRuslan Ermilov.Xr open 2 .
969916c5d2SRuslan Ermilov.Pq Dv O_RDWR | O_CREAT
97480e9923SNik Claytonis a typical value for
9895cf33c5SRuslan Ermilov.Fa flags ;
99480e9923SNik Clayton.Li 0660
100480e9923SNik Claytonis a typical value for
10195cf33c5SRuslan Ermilov.Fa mode .
10295cf33c5SRuslan Ermilov.Dv O_WRONLY
103480e9923SNik Claytonis not allowed in
10495cf33c5SRuslan Ermilov.Fa flags .
105480e9923SNik ClaytonThe pointer returned by
106480e9923SNik Clayton.Fn dbm_open
107480e9923SNik Claytonidentifies the database and is the
108480e9923SNik Clayton.Fa db
109480e9923SNik Claytonargument to the other functions.
1101fae73b1SRuslan ErmilovThe
111480e9923SNik Clayton.Fn dbm_open
1121fae73b1SRuslan Ermilovfunction
113480e9923SNik Claytonreturns
11495cf33c5SRuslan Ermilov.Dv NULL
115480e9923SNik Claytonand sets
116480e9923SNik Clayton.Va errno
11795cf33c5SRuslan Ermilovif there were any errors.
11895cf33c5SRuslan Ermilov.Pp
1191fae73b1SRuslan ErmilovThe
120480e9923SNik Clayton.Fn dbm_close db
1211fae73b1SRuslan Ermilovfunction
122480e9923SNik Claytoncloses the database.
12395cf33c5SRuslan Ermilov.Pp
1241fae73b1SRuslan ErmilovThe
125480e9923SNik Clayton.Fn dbm_store db key data flags
1261fae73b1SRuslan Ermilovfunction
127480e9923SNik Claytoninserts or replaces an entry in the database.
1282efeeba5SRuslan ErmilovThe
12995cf33c5SRuslan Ermilov.Fa flags
1302efeeba5SRuslan Ermilovargument
13195cf33c5SRuslan Ermilovis either
13295cf33c5SRuslan Ermilov.Dv DBM_INSERT
133480e9923SNik Claytonor
13495cf33c5SRuslan Ermilov.Dv DBM_REPLACE .
135480e9923SNik ClaytonIf
136480e9923SNik Clayton.Fa flags
137480e9923SNik Claytonis
13895cf33c5SRuslan Ermilov.Dv DBM_INSERT
139480e9923SNik Claytonand the database already contains an entry for
14095cf33c5SRuslan Ermilov.Fa key ,
14195cf33c5SRuslan Ermilovthat entry is not replaced.
14295cf33c5SRuslan ErmilovOtherwise the entry is replaced or inserted.
1431fae73b1SRuslan ErmilovThe
144480e9923SNik Clayton.Fn dbm_store
1451fae73b1SRuslan Ermilovfunction
146a910f192SDima Dorfmannormally returns zero but returns 1 if the entry could not be
147480e9923SNik Claytoninserted (because
148480e9923SNik Clayton.Fa flags
149480e9923SNik Claytonis
15095cf33c5SRuslan Ermilov.Dv DBM_INSERT ,
151480e9923SNik Claytonand an entry with
152480e9923SNik Clayton.Fa key
153480e9923SNik Claytonalready exists) or returns -1 and sets
154480e9923SNik Clayton.Va errno
155480e9923SNik Claytonif there were any errors.
15695cf33c5SRuslan Ermilov.Pp
1571fae73b1SRuslan ErmilovThe
158480e9923SNik Clayton.Fn dbm_fetch db key
1591fae73b1SRuslan Ermilovfunction
160480e9923SNik Claytonreturns
16195cf33c5SRuslan Ermilov.Dv NULL
162480e9923SNik Claytonor the
163480e9923SNik Clayton.Fa data
164480e9923SNik Claytoncorresponding to
16595cf33c5SRuslan Ermilov.Fa key .
16695cf33c5SRuslan Ermilov.Pp
1671fae73b1SRuslan ErmilovThe
168480e9923SNik Clayton.Fn dbm_delete db key
1691fae73b1SRuslan Ermilovfunction
170480e9923SNik Claytondeletes the entry for
17195cf33c5SRuslan Ermilov.Fa key .
1721fae73b1SRuslan ErmilovThe
173480e9923SNik Clayton.Fn dbm_delete
1741fae73b1SRuslan Ermilovfunction
175a9a4a706SPedro F. Giffuninormally returns zero or returns -1 and sets
176480e9923SNik Clayton.Va errno
177480e9923SNik Claytonif there were any errors.
17895cf33c5SRuslan Ermilov.Pp
1791fae73b1SRuslan ErmilovThe
180480e9923SNik Clayton.Fn dbm_firstkey db
1811fae73b1SRuslan Ermilovfunction
182480e9923SNik Claytonreturns the first key in the database.
1831fae73b1SRuslan ErmilovThe
184480e9923SNik Clayton.Fn dbm_nextkey db
1851fae73b1SRuslan Ermilovfunction
186480e9923SNik Claytonreturns subsequent keys.
1871fae73b1SRuslan ErmilovThe
188480e9923SNik Clayton.Fn db_firstkey
1891fae73b1SRuslan Ermilovfunction
190480e9923SNik Claytonmust be called before
191480e9923SNik Clayton.Fn dbm_nextkey .
192480e9923SNik ClaytonThe order in which keys are returned is unspecified and may appear
193480e9923SNik Claytonrandom.
1941fae73b1SRuslan ErmilovThe
195480e9923SNik Clayton.Fn dbm_nextkey
1961fae73b1SRuslan Ermilovfunction
197480e9923SNik Claytonreturns
19895cf33c5SRuslan Ermilov.Dv NULL
199480e9923SNik Claytonafter all keys have been returned.
20095cf33c5SRuslan Ermilov.Pp
2011fae73b1SRuslan ErmilovThe
202480e9923SNik Clayton.Fn dbm_error db
2031fae73b1SRuslan Ermilovfunction
204480e9923SNik Claytonreturns the
205480e9923SNik Clayton.Va errno
206480e9923SNik Claytonvalue of the most recent error.
2071fae73b1SRuslan ErmilovThe
208480e9923SNik Clayton.Fn dbm_clearerr db
2091fae73b1SRuslan Ermilovfunction
210480e9923SNik Claytonresets this value to 0 and returns 0.
21195cf33c5SRuslan Ermilov.Pp
2121fae73b1SRuslan ErmilovThe
213480e9923SNik Clayton.Fn dbm_dirfno db
2141fae73b1SRuslan Ermilovfunction
215480e9923SNik Claytonreturns the file descriptor to the database.
216480e9923SNik Clayton.Sh SEE ALSO
21795cf33c5SRuslan Ermilov.Xr open 2 ,
21895cf33c5SRuslan Ermilov.Xr dbopen 3 ,
21995cf33c5SRuslan Ermilov.Xr hash 3
220480e9923SNik Clayton.Sh STANDARDS
221480e9923SNik ClaytonThese functions (except
22295cf33c5SRuslan Ermilov.Fn dbm_dirfno )
22395cf33c5SRuslan Ermilovare included in the
22495cf33c5SRuslan Ermilov.St -susv2 .
225*4b7f35dbSGordon Bergling.Sh HISTORY
226*4b7f35dbSGordon BerglingThe functions
227*4b7f35dbSGordon Bergling.Fn dbminit ,
228*4b7f35dbSGordon Bergling.Fn fetch ,
229*4b7f35dbSGordon Bergling.Fn store ,
230*4b7f35dbSGordon Bergling.Fn delete ,
231*4b7f35dbSGordon Bergling.Fn firstkey ,
232*4b7f35dbSGordon Berglingand
233*4b7f35dbSGordon Bergling.Fn nextkey
234*4b7f35dbSGordon Berglingfirst appeared in
235*4b7f35dbSGordon Bergling.At v7 .
236