1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
.\" $NetBSD: dbm_clearerr.3,v 1.5 2010/05/05 06:55:57 jruoho Exp $
.\"
.\" Copyright (c) 2004 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Klaus Klein.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd May 5, 2010
.Dt DBM_CLEARERR 3
.Os
.Sh NAME
.Nm dbm_clearerr ,
.Nm dbm_close ,
.Nm dbm_delete ,
.Nm dbm_dirfno ,
.Nm dbm_error ,
.Nm dbm_fetch ,
.Nm dbm_firstkey ,
.Nm dbm_nextkey ,
.Nm dbm_open ,
.Nm dbm_store ,
.Nm ndbm
.Nd database functions
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In ndbm.h
.Ft int
.Fn dbm_clearerr "DBM *db"
.Ft void
.Fn dbm_close "DBM *db"
.Ft int
.Fn dbm_delete "DBM *db" "datum key"
.Ft int
.Fn dbm_dirfno "DBM *db"
.Ft int
.Fn dbm_error "DBM *db"
.Ft datum
.Fn dbm_fetch "DBM *db" "datum key"
.Ft datum
.Fn dbm_firstkey "DBM *db"
.Ft datum
.Fn dbm_nextkey "DBM *db"
.Ft DBM *
.Fn dbm_open "const char *file" "int open_flags" "mode_t file_mode"
.Ft int
.Fn dbm_store "DBM *db" "datum key" "datum content" "int store_mode"
.Sh DESCRIPTION
The
.Nm ndbm
facility provides access to hash database files.
.Pp
Two data types are fundamental to the
.Nm ndbm
facility.
.Fa DBM
serves as a handle to a database.
It is an opaque type.
.Pp
The other data type is
.Fa datum ,
which is a structure type which includes the following members:
.Bd -literal -offset indent
void * dptr
size_t dsize
.Ed
.Pp
A
.Fa datum
is thus given by
.Fa dptr
pointing at an object of
.Fa dsize
bytes in length.
.Pp
The
.Fn dbm_open
function opens a database.
The
.Fa file
argument is the pathname which the actual database file pathname
is based on.
This implementation uses a single file with the suffix
.Pa .db
appended to
.Fa file .
The
.Fa open_flags
argument has the same meaning as the
.Fa flags
argument to
.Xr open 2
except that when opening a database for write-only access the file
is opened for read/write access, and the
.Dv O_APPEND
flag must not be specified.
The
.Fa file_mode
argument has the same meaning as the
.Fa mode
argument to
.Xr open 2 .
.Pp
For the following functions, the
.Fa db
argument is a handle previously returned by a call to
.Fn dbm_open .
.Pp
The
.Fn dbm_close
function closes a database.
.Pp
The
.Fn dbm_fetch
function retrieves a record from the database.
The
.Fa key
argument is a
.Fa datum
that identifies the record to be fetched.
.Pp
The
.Fn dbm_store
function stores a record into the database.
The
.Fa key
argument is a
.Fa datum
that identifies the record to be stored.
The
.Fa content
argument is a
.Fa datum
that specifies the value of the record to be stored.
The
.Fa store_mode
argument specifies the behavior of
.Fn dbm_store
if a record matching
.Fa key
is already present in the database,
.Fa db .
.Fa store_mode
must be one of the following:
.Bl -tag -width DBM_REPLACEXX -offset indent
.It Dv DBM_INSERT
If a record matching
.Fa key
is already present, it is left unchanged.
.It Dv DBM_REPLACE
If a record matching
.Fa key
is already present, its value is replaced by
.Fa content .
.El
.Pp
If no record matching
.Fa key
is present, a new record is inserted regardless of
.Fa store_mode .
.Pp
The
.Fn dbm_delete
function deletes a record from the database.
The
.Fa key
argument is a
.Fa datum
that identifies the record to be deleted.
.Pp
The
.Fn dbm_firstkey
function returns the first key in the database.
.Pp
The
.Fn dbm_nextkey
function returns the next key in the database.
In order to be meaningful, it must be preceded by a call to
.Fn dbm_firstkey .
.Pp
The
.Fn dbm_error
function returns the error indicator of the database.
.Pp
The
.Fn dbm_clearerr
function clears the error indicator of the database.
.Pp
The
.Fn dbm_dirfno
function returns the file descriptor of the underlying database file.
.Sh IMPLEMENTATION NOTES
The
.Nm ndbm
facility is implemented on top of the
.Xr hash 3
access method of the
.Xr db 3
database facility.
.Sh RETURN VALUES
The
.Fn dbm_open
function returns a pointer to a
.Fa DBM
when successful; otherwise a null pointer is returned.
.Pp
The
.Fn dbm_close
function returns no value.
.Pp
The
.Fn dbm_fetch
function returns a content
.Fa datum ;
if no record matching
.Fa key
was found or if an error occured, its
.Fa dptr
member is a null pointer.
.Pp
The
.Fn dbm_store
function returns 0 when then record was successfully inserted;
it returns 1 when called with
.Fa store_mode
being
.Dv DBM_INSERT
and a record matching
.Fa key
is already present;
otherwise a negative value is returned.
.Pp
The
.Fn dbm_delete
function returns 0 when the record was successfully deleted;
otherwise a negative value is returned.
.Pp
The
.Fn dbm_firstkey
and
.Fn dbm_nextkey
functions return a key
.Fa datum .
When the end of the database is reached or if an error occured, its
.Fa dptr
member is a null pointer.
.Pp
The
.Fn dbm_error
function returns 0 if the error indicator is clear;
if the error indicator is set a non-zero value is returned.
.Pp
The
.Fn dbm_clearerr
function always returns 0.
.Pp
The
.Fn dbm_dirfno
function returns the file descriptor of the underlying database file.
.Sh ERRORS
No errors are defined.
.Sh SEE ALSO
.Xr open 2 ,
.Xr db 3 ,
.Xr hash 3
.Sh STANDARDS
The
.Fn dbm_clearerr ,
.Fn dbm_close ,
.Fn dbm_delete ,
.Fn dbm_error ,
.Fn dbm_fetch ,
.Fn dbm_firstkey ,
.Fn dbm_nextkey ,
.Fn dbm_open ,
and
.Fn dbm_store
functions conform to
.St -xpg4.2
and
.St -susv2 .
The
.Fn dbm_dirfno
function is an extension.
|