]>
Commit | Line | Data |
---|---|---|
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 |
83 | Database access functions. | |
84 | These functions are implemented using | |
85 | .Xr dbopen 3 | |
86 | with a | |
87 | .Xr hash 3 | |
88 | database. | |
89 | .Pp | |
90 | .Vt datum | |
91 | is declared in | |
3d9156a7 | 92 | .In ndbm.h : |
5b2abdfb A |
93 | .Bd -literal |
94 | typedef struct { | |
95 | char *dptr; | |
96 | int dsize; | |
97 | } datum; | |
98 | .Ed | |
99 | .Pp | |
59e0d9fe | 100 | The |
ad3c9f2a | 101 | .Fn dbm_open file open_flags file_mode |
59e0d9fe | 102 | function |
ad3c9f2a | 103 | opens or creates a database file. |
59e0d9fe | 104 | The |
ad3c9f2a | 105 | .Fa file |
59e0d9fe | 106 | argument |
5b2abdfb A |
107 | is the basename of the file containing |
108 | the database; the actual database has a | |
109 | .Pa .db | |
110 | suffix. | |
111 | I.e., if | |
ad3c9f2a | 112 | .Fa file |
5b2abdfb A |
113 | is |
114 | .Qq Li /home/me/mystuff | |
115 | then the actual database is in the file | |
116 | .Pa /home/me/mystuff.db . | |
59e0d9fe | 117 | The |
ad3c9f2a | 118 | .Fa open_flags |
5b2abdfb | 119 | and |
ad3c9f2a | 120 | .Fa file_mode |
59e0d9fe | 121 | arguments |
5b2abdfb A |
122 | are passed to |
123 | .Xr open 2 . | |
124 | .Pq Dv O_RDWR | O_CREAT | |
125 | is a typical value for | |
ad3c9f2a | 126 | .Fa open_flags ; |
5b2abdfb A |
127 | .Li 0660 |
128 | is a typical value for | |
ad3c9f2a | 129 | .Fa file_mode . |
5b2abdfb | 130 | .Dv O_WRONLY |
1f2f436a | 131 | is not allowed in |
ad3c9f2a | 132 | .Fa open_flags . |
5b2abdfb A |
133 | The pointer returned by |
134 | .Fn dbm_open | |
135 | identifies the database and is the | |
136 | .Fa db | |
137 | argument to the other functions. | |
59e0d9fe | 138 | The |
5b2abdfb | 139 | .Fn dbm_open |
59e0d9fe | 140 | function |
5b2abdfb A |
141 | returns |
142 | .Dv NULL | |
143 | and sets | |
144 | .Va errno | |
145 | if there were any errors. | |
146 | .Pp | |
59e0d9fe | 147 | The |
5b2abdfb | 148 | .Fn dbm_close db |
59e0d9fe | 149 | function |
5b2abdfb | 150 | closes the database. |
5b2abdfb | 151 | .Pp |
59e0d9fe | 152 | The |
ad3c9f2a | 153 | .Fn dbm_store db key content store_mode |
59e0d9fe | 154 | function |
5b2abdfb | 155 | inserts or replaces an entry in the database. |
59e0d9fe | 156 | The |
ad3c9f2a | 157 | .Fa store_mode |
59e0d9fe | 158 | argument |
5b2abdfb A |
159 | is either |
160 | .Dv DBM_INSERT | |
161 | or | |
162 | .Dv DBM_REPLACE . | |
163 | If | |
ad3c9f2a | 164 | .Fa store_mode |
5b2abdfb A |
165 | is |
166 | .Dv DBM_INSERT | |
167 | and the database already contains an entry for | |
168 | .Fa key , | |
169 | that entry is not replaced. | |
170 | Otherwise the entry is replaced or inserted. | |
59e0d9fe | 171 | The |
5b2abdfb | 172 | .Fn dbm_store |
59e0d9fe | 173 | function |
5b2abdfb A |
174 | normally returns zero but returns 1 if the entry could not be |
175 | inserted (because | |
ad3c9f2a | 176 | .Fa store_mode |
5b2abdfb A |
177 | is |
178 | .Dv DBM_INSERT , | |
179 | and an entry with | |
180 | .Fa key | |
181 | already exists) or returns -1 and sets | |
182 | .Va errno | |
183 | if there were any errors. | |
184 | .Pp | |
59e0d9fe | 185 | The |
5b2abdfb | 186 | .Fn dbm_fetch db key |
59e0d9fe | 187 | function |
5b2abdfb A |
188 | returns |
189 | .Dv NULL | |
190 | or the | |
ad3c9f2a | 191 | .Fa content |
5b2abdfb A |
192 | corresponding to |
193 | .Fa key . | |
194 | .Pp | |
59e0d9fe | 195 | The |
5b2abdfb | 196 | .Fn dbm_delete db key |
59e0d9fe | 197 | function |
5b2abdfb A |
198 | deletes the entry for |
199 | .Fa key . | |
59e0d9fe | 200 | The |
5b2abdfb | 201 | .Fn dbm_delete |
59e0d9fe | 202 | function |
5b2abdfb A |
203 | normally returns zero but returns 1 if there was no entry with |
204 | .Fa key | |
205 | in the database or returns -1 and sets | |
206 | .Va errno | |
207 | if there were any errors. | |
208 | .Pp | |
59e0d9fe | 209 | The |
5b2abdfb | 210 | .Fn dbm_firstkey db |
59e0d9fe | 211 | function |
5b2abdfb | 212 | returns the first key in the database. |
59e0d9fe | 213 | The |
5b2abdfb | 214 | .Fn dbm_nextkey db |
59e0d9fe | 215 | function |
5b2abdfb | 216 | returns subsequent keys. |
59e0d9fe | 217 | The |
5b2abdfb | 218 | .Fn db_firstkey |
59e0d9fe | 219 | function |
5b2abdfb A |
220 | must be called before |
221 | .Fn dbm_nextkey . | |
222 | The order in which keys are returned is unspecified and may appear | |
223 | random. | |
59e0d9fe | 224 | The |
5b2abdfb | 225 | .Fn dbm_nextkey |
59e0d9fe | 226 | function |
5b2abdfb A |
227 | returns |
228 | .Dv NULL | |
229 | after all keys have been returned. | |
230 | .Pp | |
59e0d9fe | 231 | The |
5b2abdfb | 232 | .Fn dbm_error db |
59e0d9fe | 233 | function |
5b2abdfb A |
234 | returns the |
235 | .Va errno | |
236 | value of the most recent error. | |
59e0d9fe | 237 | The |
5b2abdfb | 238 | .Fn dbm_clearerr db |
59e0d9fe | 239 | function |
5b2abdfb A |
240 | resets this value to 0 and returns 0. |
241 | .Pp | |
59e0d9fe | 242 | The |
5b2abdfb | 243 | .Fn dbm_dirfno db |
59e0d9fe | 244 | function |
5b2abdfb | 245 | returns the file descriptor to the database. |
ad3c9f2a A |
246 | .Sh LEGACY SYNOPSIS |
247 | .Fd #include <fcntl.h> | |
248 | .Fd #include <ndbm.h> | |
249 | .Pp | |
250 | The include file | |
251 | .In ndbm.h | |
252 | is 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 | |
263 | has 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 |
271 | These functions (except | |
272 | .Fn dbm_dirfno ) | |
273 | are included in the | |
274 | .St -susv2 . |