]> git.saurik.com Git - apple/libc.git/blame - db/man/FreeBSD/dbm.3
Libc-1439.100.3.tar.gz
[apple/libc.git] / db / man / FreeBSD / dbm.3
CommitLineData
5b2abdfb
A
1.\" Copyright (c) 1999 Tim Singletary
2.\" No copyright is claimed.
3.\"
4.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
5.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
6.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
8.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
9.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
10.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
11.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
12.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
13.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
14.\" SUCH DAMAGE.
15.\"
1f2f436a 16.\" $FreeBSD: src/lib/libc/db/man/dbm.3,v 1.10 2009/01/30 15:28:35 gabor Exp $
5b2abdfb 17.\"
1f2f436a 18.Dd April 16, 2006
5b2abdfb
A
19.Dt DBM 3
20.Os
21.Sh NAME
22.Nm dbm_clearerr ,
23.Nm dbm_close ,
24.Nm dbm_delete ,
25.Nm dbm_dirfno ,
26.Nm dbm_error ,
27.Nm dbm_fetch ,
28.Nm dbm_firstkey ,
29.Nm dbm_nextkey ,
30.Nm dbm_open ,
31.Nm dbm_store
32.Nd database access functions
33.Sh SYNOPSIS
5b2abdfb 34.In ndbm.h
ad3c9f2a
A
35.Ft int
36.Fo dbm_clearerr
37.Fa "DBM *db"
38.Fc
5b2abdfb 39.Ft void
ad3c9f2a
A
40.Fo dbm_close
41.Fa "DBM *db"
42.Fc
5b2abdfb 43.Ft int
ad3c9f2a
A
44.Fo dbm_delete
45.Fa "DBM *db"
46.Fa "datum key"
47.Fc
48.Ft int
49.Fo dbm_dirfno
50.Fa "DBM *db"
51.Fc
5b2abdfb 52.Ft int
ad3c9f2a
A
53.Fo dbm_error
54.Fa "DBM *db"
55.Fc
5b2abdfb 56.Ft datum
ad3c9f2a
A
57.Fo dbm_fetch
58.Fa "DBM *db"
59.Fa "datum key"
60.Fc
5b2abdfb 61.Ft datum
ad3c9f2a
A
62.Fo dbm_firstkey
63.Fa "DBM *db"
64.Fc
65.Ft datum
66.Fo dbm_nextkey
67.Fa "DBM *db"
68.Fc
69.Ft DBM *
70.Fo dbm_open
71.Fa "const char *file"
72.Fa "int open_flags"
73.Fa "mode_t file_mode"
74.Fc
5b2abdfb 75.Ft int
ad3c9f2a
A
76.Fo dbm_store
77.Fa "DBM *db"
78.Fa "datum key"
79.Fa "datum content"
80.Fa "int store_mode"
81.Fc
5b2abdfb
A
82.Sh DESCRIPTION
83Database access functions.
84These functions are implemented using
85.Xr dbopen 3
86with a
87.Xr hash 3
88database.
89.Pp
90.Vt datum
91is declared in
3d9156a7 92.In ndbm.h :
5b2abdfb
A
93.Bd -literal
94typedef struct {
95 char *dptr;
96 int dsize;
97} datum;
98.Ed
99.Pp
59e0d9fe 100The
ad3c9f2a 101.Fn dbm_open file open_flags file_mode
59e0d9fe 102function
ad3c9f2a 103opens or creates a database file.
59e0d9fe 104The
ad3c9f2a 105.Fa file
59e0d9fe 106argument
5b2abdfb
A
107is the basename of the file containing
108the database; the actual database has a
109.Pa .db
110suffix.
111I.e., if
ad3c9f2a 112.Fa file
5b2abdfb
A
113is
114.Qq Li /home/me/mystuff
115then the actual database is in the file
116.Pa /home/me/mystuff.db .
59e0d9fe 117The
ad3c9f2a 118.Fa open_flags
5b2abdfb 119and
ad3c9f2a 120.Fa file_mode
59e0d9fe 121arguments
5b2abdfb
A
122are passed to
123.Xr open 2 .
124.Pq Dv O_RDWR | O_CREAT
125is a typical value for
ad3c9f2a 126.Fa open_flags ;
5b2abdfb
A
127.Li 0660
128is a typical value for
ad3c9f2a 129.Fa file_mode .
5b2abdfb 130.Dv O_WRONLY
1f2f436a 131is not allowed in
ad3c9f2a 132.Fa open_flags .
5b2abdfb
A
133The pointer returned by
134.Fn dbm_open
135identifies the database and is the
136.Fa db
137argument to the other functions.
59e0d9fe 138The
5b2abdfb 139.Fn dbm_open
59e0d9fe 140function
5b2abdfb
A
141returns
142.Dv NULL
143and sets
144.Va errno
145if there were any errors.
146.Pp
59e0d9fe 147The
5b2abdfb 148.Fn dbm_close db
59e0d9fe 149function
5b2abdfb 150closes the database.
5b2abdfb 151.Pp
59e0d9fe 152The
ad3c9f2a 153.Fn dbm_store db key content store_mode
59e0d9fe 154function
5b2abdfb 155inserts or replaces an entry in the database.
59e0d9fe 156The
ad3c9f2a 157.Fa store_mode
59e0d9fe 158argument
5b2abdfb
A
159is either
160.Dv DBM_INSERT
161or
162.Dv DBM_REPLACE .
163If
ad3c9f2a 164.Fa store_mode
5b2abdfb
A
165is
166.Dv DBM_INSERT
167and the database already contains an entry for
168.Fa key ,
169that entry is not replaced.
170Otherwise the entry is replaced or inserted.
59e0d9fe 171The
5b2abdfb 172.Fn dbm_store
59e0d9fe 173function
5b2abdfb
A
174normally returns zero but returns 1 if the entry could not be
175inserted (because
ad3c9f2a 176.Fa store_mode
5b2abdfb
A
177is
178.Dv DBM_INSERT ,
179and an entry with
180.Fa key
181already exists) or returns -1 and sets
182.Va errno
183if there were any errors.
184.Pp
59e0d9fe 185The
5b2abdfb 186.Fn dbm_fetch db key
59e0d9fe 187function
5b2abdfb
A
188returns
189.Dv NULL
190or the
ad3c9f2a 191.Fa content
5b2abdfb
A
192corresponding to
193.Fa key .
194.Pp
59e0d9fe 195The
5b2abdfb 196.Fn dbm_delete db key
59e0d9fe 197function
5b2abdfb
A
198deletes the entry for
199.Fa key .
59e0d9fe 200The
5b2abdfb 201.Fn dbm_delete
59e0d9fe 202function
5b2abdfb
A
203normally returns zero but returns 1 if there was no entry with
204.Fa key
205in the database or returns -1 and sets
206.Va errno
207if there were any errors.
208.Pp
59e0d9fe 209The
5b2abdfb 210.Fn dbm_firstkey db
59e0d9fe 211function
5b2abdfb 212returns the first key in the database.
59e0d9fe 213The
5b2abdfb 214.Fn dbm_nextkey db
59e0d9fe 215function
5b2abdfb 216returns subsequent keys.
59e0d9fe 217The
5b2abdfb 218.Fn db_firstkey
59e0d9fe 219function
5b2abdfb
A
220must be called before
221.Fn dbm_nextkey .
222The order in which keys are returned is unspecified and may appear
223random.
59e0d9fe 224The
5b2abdfb 225.Fn dbm_nextkey
59e0d9fe 226function
5b2abdfb
A
227returns
228.Dv NULL
229after all keys have been returned.
230.Pp
59e0d9fe 231The
5b2abdfb 232.Fn dbm_error db
59e0d9fe 233function
5b2abdfb
A
234returns the
235.Va errno
236value of the most recent error.
59e0d9fe 237The
5b2abdfb 238.Fn dbm_clearerr db
59e0d9fe 239function
5b2abdfb
A
240resets this value to 0 and returns 0.
241.Pp
59e0d9fe 242The
5b2abdfb 243.Fn dbm_dirfno db
59e0d9fe 244function
5b2abdfb 245returns the file descriptor to the database.
ad3c9f2a
A
246.Sh LEGACY SYNOPSIS
247.Fd #include <fcntl.h>
248.Fd #include <ndbm.h>
249.Pp
250The include file
251.In ndbm.h
252is necessary for all functions.
253.Pp
254.Ft DBM *
255.br
256.Fo dbm_open
257.Fa "const char *file"
258.Fa "int open_flags"
259.Fa "int file_mode"
260.Fc ;
261.Pp
262.Fa file_mode
263has type
264.Vt int .
5b2abdfb
A
265.Sh SEE ALSO
266.Xr open 2 ,
267.Xr dbopen 3 ,
ad3c9f2a
A
268.Xr hash 3 ,
269.Xr compat 5
5b2abdfb
A
270.Sh STANDARDS
271These functions (except
272.Fn dbm_dirfno )
273are included in the
274.St -susv2 .