xref: /freebsd/lib/libc/db/man/dbm.3 (revision 4b7f35db44cbf901e994fc9a4bcd4c98ebe8c4a1)
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.\"
16480e9923SNik Clayton.\" $FreeBSD$
17480e9923SNik Clayton.\"
18*4b7f35dbSGordon Bergling.Dd April 2, 2022
1995cf33c5SRuslan Ermilov.Dt DBM 3
2095cf33c5SRuslan Ermilov.Os
21480e9923SNik Clayton.Sh NAME
2295cf33c5SRuslan Ermilov.Nm dbm_clearerr ,
2395cf33c5SRuslan Ermilov.Nm dbm_close ,
2495cf33c5SRuslan Ermilov.Nm dbm_delete ,
2595cf33c5SRuslan Ermilov.Nm dbm_dirfno ,
2695cf33c5SRuslan Ermilov.Nm dbm_error ,
2795cf33c5SRuslan Ermilov.Nm dbm_fetch ,
2895cf33c5SRuslan Ermilov.Nm dbm_firstkey ,
2995cf33c5SRuslan Ermilov.Nm dbm_nextkey ,
3095cf33c5SRuslan Ermilov.Nm dbm_open ,
31480e9923SNik Clayton.Nm dbm_store
32480e9923SNik Clayton.Nd database access functions
33480e9923SNik Clayton.Sh SYNOPSIS
3432eef9aeSRuslan Ermilov.In fcntl.h
3532eef9aeSRuslan Ermilov.In ndbm.h
36480e9923SNik Clayton.Ft DBM *
37de1d2695SEd Schouten.Fn dbm_open "const char *base" "int flags" "mode_t mode"
38480e9923SNik Clayton.Ft void
39480e9923SNik Clayton.Fn dbm_close "DBM *db"
40480e9923SNik Clayton.Ft int
41480e9923SNik Clayton.Fn dbm_store "DBM *db" "datum key" "datum data" "int flags"
42480e9923SNik Clayton.Ft datum
43480e9923SNik Clayton.Fn dbm_fetch "DBM *db" "datum key"
44480e9923SNik Clayton.Ft int
45480e9923SNik Clayton.Fn dbm_delete "DBM *db" "datum key"
46480e9923SNik Clayton.Ft datum
47480e9923SNik Clayton.Fn dbm_firstkey "DBM *db"
48480e9923SNik Clayton.Ft datum
49480e9923SNik Clayton.Fn dbm_nextkey "DBM *db"
50480e9923SNik Clayton.Ft int
51480e9923SNik Clayton.Fn dbm_error "DBM *db"
52480e9923SNik Clayton.Ft int
53480e9923SNik Clayton.Fn dbm_clearerr "DBM *db"
54480e9923SNik Clayton.Ft int
55480e9923SNik Clayton.Fn dbm_dirfno "DBM *db"
56480e9923SNik Clayton.Sh DESCRIPTION
57480e9923SNik ClaytonDatabase access functions.
58480e9923SNik ClaytonThese functions are implemented using
5995cf33c5SRuslan Ermilov.Xr dbopen 3
60480e9923SNik Claytonwith a
6195cf33c5SRuslan Ermilov.Xr hash 3
62480e9923SNik Claytondatabase.
6395cf33c5SRuslan Ermilov.Pp
6495cf33c5SRuslan Ermilov.Vt datum
65480e9923SNik Claytonis declared in
66fe08efe6SRuslan Ermilov.In ndbm.h :
67480e9923SNik Clayton.Bd -literal
68480e9923SNik Claytontypedef struct {
692fed5061SEd Schouten	void *dptr;
70480e9923SNik Clayton	int dsize;
71480e9923SNik Clayton} datum;
72480e9923SNik Clayton.Ed
7395cf33c5SRuslan Ermilov.Pp
741fae73b1SRuslan ErmilovThe
75480e9923SNik Clayton.Fn dbm_open base flags mode
761fae73b1SRuslan Ermilovfunction
77480e9923SNik Claytonopens or creates a database.
782efeeba5SRuslan ErmilovThe
7995cf33c5SRuslan Ermilov.Fa base
802efeeba5SRuslan Ermilovargument
8195cf33c5SRuslan Ermilovis the basename of the file containing
82480e9923SNik Claytonthe database; the actual database has a
8395cf33c5SRuslan Ermilov.Pa .db
8495cf33c5SRuslan Ermilovsuffix.
8595cf33c5SRuslan ErmilovI.e., if
86480e9923SNik Clayton.Fa base
87480e9923SNik Claytonis
8895cf33c5SRuslan Ermilov.Qq Li /home/me/mystuff
89480e9923SNik Claytonthen the actual database is in the file
9095cf33c5SRuslan Ermilov.Pa /home/me/mystuff.db .
912efeeba5SRuslan ErmilovThe
9295cf33c5SRuslan Ermilov.Fa flags
9395cf33c5SRuslan Ermilovand
9495cf33c5SRuslan Ermilov.Fa mode
952efeeba5SRuslan Ermilovarguments
9695cf33c5SRuslan Ermilovare passed to
9795cf33c5SRuslan Ermilov.Xr open 2 .
989916c5d2SRuslan Ermilov.Pq Dv O_RDWR | O_CREAT
99480e9923SNik Claytonis a typical value for
10095cf33c5SRuslan Ermilov.Fa flags ;
101480e9923SNik Clayton.Li 0660
102480e9923SNik Claytonis a typical value for
10395cf33c5SRuslan Ermilov.Fa mode .
10495cf33c5SRuslan Ermilov.Dv O_WRONLY
105480e9923SNik Claytonis not allowed in
10695cf33c5SRuslan Ermilov.Fa flags .
107480e9923SNik ClaytonThe pointer returned by
108480e9923SNik Clayton.Fn dbm_open
109480e9923SNik Claytonidentifies the database and is the
110480e9923SNik Clayton.Fa db
111480e9923SNik Claytonargument to the other functions.
1121fae73b1SRuslan ErmilovThe
113480e9923SNik Clayton.Fn dbm_open
1141fae73b1SRuslan Ermilovfunction
115480e9923SNik Claytonreturns
11695cf33c5SRuslan Ermilov.Dv NULL
117480e9923SNik Claytonand sets
118480e9923SNik Clayton.Va errno
11995cf33c5SRuslan Ermilovif there were any errors.
12095cf33c5SRuslan Ermilov.Pp
1211fae73b1SRuslan ErmilovThe
122480e9923SNik Clayton.Fn dbm_close db
1231fae73b1SRuslan Ermilovfunction
124480e9923SNik Claytoncloses the database.
12595cf33c5SRuslan Ermilov.Pp
1261fae73b1SRuslan ErmilovThe
127480e9923SNik Clayton.Fn dbm_store db key data flags
1281fae73b1SRuslan Ermilovfunction
129480e9923SNik Claytoninserts or replaces an entry in the database.
1302efeeba5SRuslan ErmilovThe
13195cf33c5SRuslan Ermilov.Fa flags
1322efeeba5SRuslan Ermilovargument
13395cf33c5SRuslan Ermilovis either
13495cf33c5SRuslan Ermilov.Dv DBM_INSERT
135480e9923SNik Claytonor
13695cf33c5SRuslan Ermilov.Dv DBM_REPLACE .
137480e9923SNik ClaytonIf
138480e9923SNik Clayton.Fa flags
139480e9923SNik Claytonis
14095cf33c5SRuslan Ermilov.Dv DBM_INSERT
141480e9923SNik Claytonand the database already contains an entry for
14295cf33c5SRuslan Ermilov.Fa key ,
14395cf33c5SRuslan Ermilovthat entry is not replaced.
14495cf33c5SRuslan ErmilovOtherwise the entry is replaced or inserted.
1451fae73b1SRuslan ErmilovThe
146480e9923SNik Clayton.Fn dbm_store
1471fae73b1SRuslan Ermilovfunction
148a910f192SDima Dorfmannormally returns zero but returns 1 if the entry could not be
149480e9923SNik Claytoninserted (because
150480e9923SNik Clayton.Fa flags
151480e9923SNik Claytonis
15295cf33c5SRuslan Ermilov.Dv DBM_INSERT ,
153480e9923SNik Claytonand an entry with
154480e9923SNik Clayton.Fa key
155480e9923SNik Claytonalready exists) or returns -1 and sets
156480e9923SNik Clayton.Va errno
157480e9923SNik Claytonif there were any errors.
15895cf33c5SRuslan Ermilov.Pp
1591fae73b1SRuslan ErmilovThe
160480e9923SNik Clayton.Fn dbm_fetch db key
1611fae73b1SRuslan Ermilovfunction
162480e9923SNik Claytonreturns
16395cf33c5SRuslan Ermilov.Dv NULL
164480e9923SNik Claytonor the
165480e9923SNik Clayton.Fa data
166480e9923SNik Claytoncorresponding to
16795cf33c5SRuslan Ermilov.Fa key .
16895cf33c5SRuslan Ermilov.Pp
1691fae73b1SRuslan ErmilovThe
170480e9923SNik Clayton.Fn dbm_delete db key
1711fae73b1SRuslan Ermilovfunction
172480e9923SNik Claytondeletes the entry for
17395cf33c5SRuslan Ermilov.Fa key .
1741fae73b1SRuslan ErmilovThe
175480e9923SNik Clayton.Fn dbm_delete
1761fae73b1SRuslan Ermilovfunction
177a9a4a706SPedro F. Giffuninormally returns zero or returns -1 and sets
178480e9923SNik Clayton.Va errno
179480e9923SNik Claytonif there were any errors.
18095cf33c5SRuslan Ermilov.Pp
1811fae73b1SRuslan ErmilovThe
182480e9923SNik Clayton.Fn dbm_firstkey db
1831fae73b1SRuslan Ermilovfunction
184480e9923SNik Claytonreturns the first key in the database.
1851fae73b1SRuslan ErmilovThe
186480e9923SNik Clayton.Fn dbm_nextkey db
1871fae73b1SRuslan Ermilovfunction
188480e9923SNik Claytonreturns subsequent keys.
1891fae73b1SRuslan ErmilovThe
190480e9923SNik Clayton.Fn db_firstkey
1911fae73b1SRuslan Ermilovfunction
192480e9923SNik Claytonmust be called before
193480e9923SNik Clayton.Fn dbm_nextkey .
194480e9923SNik ClaytonThe order in which keys are returned is unspecified and may appear
195480e9923SNik Claytonrandom.
1961fae73b1SRuslan ErmilovThe
197480e9923SNik Clayton.Fn dbm_nextkey
1981fae73b1SRuslan Ermilovfunction
199480e9923SNik Claytonreturns
20095cf33c5SRuslan Ermilov.Dv NULL
201480e9923SNik Claytonafter all keys have been returned.
20295cf33c5SRuslan Ermilov.Pp
2031fae73b1SRuslan ErmilovThe
204480e9923SNik Clayton.Fn dbm_error db
2051fae73b1SRuslan Ermilovfunction
206480e9923SNik Claytonreturns the
207480e9923SNik Clayton.Va errno
208480e9923SNik Claytonvalue of the most recent error.
2091fae73b1SRuslan ErmilovThe
210480e9923SNik Clayton.Fn dbm_clearerr db
2111fae73b1SRuslan Ermilovfunction
212480e9923SNik Claytonresets this value to 0 and returns 0.
21395cf33c5SRuslan Ermilov.Pp
2141fae73b1SRuslan ErmilovThe
215480e9923SNik Clayton.Fn dbm_dirfno db
2161fae73b1SRuslan Ermilovfunction
217480e9923SNik Claytonreturns the file descriptor to the database.
218480e9923SNik Clayton.Sh SEE ALSO
21995cf33c5SRuslan Ermilov.Xr open 2 ,
22095cf33c5SRuslan Ermilov.Xr dbopen 3 ,
22195cf33c5SRuslan Ermilov.Xr hash 3
222480e9923SNik Clayton.Sh STANDARDS
223480e9923SNik ClaytonThese functions (except
22495cf33c5SRuslan Ermilov.Fn dbm_dirfno )
22595cf33c5SRuslan Ermilovare included in the
22695cf33c5SRuslan Ermilov.St -susv2 .
227*4b7f35dbSGordon Bergling.Sh HISTORY
228*4b7f35dbSGordon BerglingThe functions
229*4b7f35dbSGordon Bergling.Fn dbminit ,
230*4b7f35dbSGordon Bergling.Fn fetch ,
231*4b7f35dbSGordon Bergling.Fn store ,
232*4b7f35dbSGordon Bergling.Fn delete ,
233*4b7f35dbSGordon Bergling.Fn firstkey ,
234*4b7f35dbSGordon Berglingand
235*4b7f35dbSGordon Bergling.Fn nextkey
236*4b7f35dbSGordon Berglingfirst appeared in
237*4b7f35dbSGordon Bergling.At v7 .
238