]>
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 | .\" | |
3d9156a7 | 16 | .\" $FreeBSD: src/lib/libc/db/man/dbm.3,v 1.8 2003/09/08 19:57:13 ru Exp $ |
5b2abdfb A |
17 | .\" |
18 | .\" Note: The date here should be updated whenever a non-trivial | |
19 | .\" change is made to the manual page. | |
20 | .Dd July 7, 1999 | |
21 | .Dt DBM 3 | |
22 | .Os | |
23 | .Sh NAME | |
24 | .Nm dbm_clearerr , | |
25 | .Nm dbm_close , | |
26 | .Nm dbm_delete , | |
27 | .Nm dbm_dirfno , | |
28 | .Nm dbm_error , | |
29 | .Nm dbm_fetch , | |
30 | .Nm dbm_firstkey , | |
31 | .Nm dbm_nextkey , | |
32 | .Nm dbm_open , | |
33 | .Nm dbm_store | |
34 | .Nd database access functions | |
35 | .Sh SYNOPSIS | |
36 | .In fcntl.h | |
37 | .In ndbm.h | |
38 | .Ft DBM * | |
39 | .Fn dbm_open "const char *base" "int flags" "int mode" | |
40 | .Ft void | |
41 | .Fn dbm_close "DBM *db" | |
42 | .Ft int | |
43 | .Fn dbm_store "DBM *db" "datum key" "datum data" "int flags" | |
44 | .Ft datum | |
45 | .Fn dbm_fetch "DBM *db" "datum key" | |
46 | .Ft int | |
47 | .Fn dbm_delete "DBM *db" "datum key" | |
48 | .Ft datum | |
49 | .Fn dbm_firstkey "DBM *db" | |
50 | .Ft datum | |
51 | .Fn dbm_nextkey "DBM *db" | |
52 | .Ft int | |
53 | .Fn dbm_error "DBM *db" | |
54 | .Ft int | |
55 | .Fn dbm_clearerr "DBM *db" | |
56 | .Ft int | |
57 | .Fn dbm_dirfno "DBM *db" | |
58 | .Sh DESCRIPTION | |
59 | Database access functions. | |
60 | These functions are implemented using | |
61 | .Xr dbopen 3 | |
62 | with a | |
63 | .Xr hash 3 | |
64 | database. | |
65 | .Pp | |
66 | .Vt datum | |
67 | is declared in | |
3d9156a7 | 68 | .In ndbm.h : |
5b2abdfb A |
69 | .Bd -literal |
70 | typedef struct { | |
71 | char *dptr; | |
72 | int dsize; | |
73 | } datum; | |
74 | .Ed | |
75 | .Pp | |
59e0d9fe | 76 | The |
5b2abdfb | 77 | .Fn dbm_open base flags mode |
59e0d9fe | 78 | function |
5b2abdfb | 79 | opens or creates a database. |
59e0d9fe | 80 | The |
5b2abdfb | 81 | .Fa base |
59e0d9fe | 82 | argument |
5b2abdfb A |
83 | is the basename of the file containing |
84 | the database; the actual database has a | |
85 | .Pa .db | |
86 | suffix. | |
87 | I.e., if | |
88 | .Fa base | |
89 | is | |
90 | .Qq Li /home/me/mystuff | |
91 | then the actual database is in the file | |
92 | .Pa /home/me/mystuff.db . | |
59e0d9fe | 93 | The |
5b2abdfb A |
94 | .Fa flags |
95 | and | |
96 | .Fa mode | |
59e0d9fe | 97 | arguments |
5b2abdfb A |
98 | are passed to |
99 | .Xr open 2 . | |
100 | .Pq Dv O_RDWR | O_CREAT | |
101 | is a typical value for | |
102 | .Fa flags ; | |
103 | .Li 0660 | |
104 | is a typical value for | |
105 | .Fa mode . | |
106 | .Dv O_WRONLY | |
107 | is not allowed in | |
108 | .Fa flags . | |
109 | The pointer returned by | |
110 | .Fn dbm_open | |
111 | identifies the database and is the | |
112 | .Fa db | |
113 | argument to the other functions. | |
59e0d9fe | 114 | The |
5b2abdfb | 115 | .Fn dbm_open |
59e0d9fe | 116 | function |
5b2abdfb A |
117 | returns |
118 | .Dv NULL | |
119 | and sets | |
120 | .Va errno | |
121 | if there were any errors. | |
122 | .Pp | |
59e0d9fe | 123 | The |
5b2abdfb | 124 | .Fn dbm_close db |
59e0d9fe | 125 | function |
5b2abdfb | 126 | closes the database. |
59e0d9fe | 127 | The |
5b2abdfb | 128 | .Fn dbm_close |
59e0d9fe | 129 | function |
5b2abdfb A |
130 | normally returns zero. |
131 | .Pp | |
59e0d9fe | 132 | The |
5b2abdfb | 133 | .Fn dbm_store db key data flags |
59e0d9fe | 134 | function |
5b2abdfb | 135 | inserts or replaces an entry in the database. |
59e0d9fe | 136 | The |
5b2abdfb | 137 | .Fa flags |
59e0d9fe | 138 | argument |
5b2abdfb A |
139 | is either |
140 | .Dv DBM_INSERT | |
141 | or | |
142 | .Dv DBM_REPLACE . | |
143 | If | |
144 | .Fa flags | |
145 | is | |
146 | .Dv DBM_INSERT | |
147 | and the database already contains an entry for | |
148 | .Fa key , | |
149 | that entry is not replaced. | |
150 | Otherwise the entry is replaced or inserted. | |
59e0d9fe | 151 | The |
5b2abdfb | 152 | .Fn dbm_store |
59e0d9fe | 153 | function |
5b2abdfb A |
154 | normally returns zero but returns 1 if the entry could not be |
155 | inserted (because | |
156 | .Fa flags | |
157 | is | |
158 | .Dv DBM_INSERT , | |
159 | and an entry with | |
160 | .Fa key | |
161 | already exists) or returns -1 and sets | |
162 | .Va errno | |
163 | if there were any errors. | |
164 | .Pp | |
59e0d9fe | 165 | The |
5b2abdfb | 166 | .Fn dbm_fetch db key |
59e0d9fe | 167 | function |
5b2abdfb A |
168 | returns |
169 | .Dv NULL | |
170 | or the | |
171 | .Fa data | |
172 | corresponding to | |
173 | .Fa key . | |
174 | .Pp | |
59e0d9fe | 175 | The |
5b2abdfb | 176 | .Fn dbm_delete db key |
59e0d9fe | 177 | function |
5b2abdfb A |
178 | deletes the entry for |
179 | .Fa key . | |
59e0d9fe | 180 | The |
5b2abdfb | 181 | .Fn dbm_delete |
59e0d9fe | 182 | function |
5b2abdfb A |
183 | normally returns zero but returns 1 if there was no entry with |
184 | .Fa key | |
185 | in the database or returns -1 and sets | |
186 | .Va errno | |
187 | if there were any errors. | |
188 | .Pp | |
59e0d9fe | 189 | The |
5b2abdfb | 190 | .Fn dbm_firstkey db |
59e0d9fe | 191 | function |
5b2abdfb | 192 | returns the first key in the database. |
59e0d9fe | 193 | The |
5b2abdfb | 194 | .Fn dbm_nextkey db |
59e0d9fe | 195 | function |
5b2abdfb | 196 | returns subsequent keys. |
59e0d9fe | 197 | The |
5b2abdfb | 198 | .Fn db_firstkey |
59e0d9fe | 199 | function |
5b2abdfb A |
200 | must be called before |
201 | .Fn dbm_nextkey . | |
202 | The order in which keys are returned is unspecified and may appear | |
203 | random. | |
59e0d9fe | 204 | The |
5b2abdfb | 205 | .Fn dbm_nextkey |
59e0d9fe | 206 | function |
5b2abdfb A |
207 | returns |
208 | .Dv NULL | |
209 | after all keys have been returned. | |
210 | .Pp | |
59e0d9fe | 211 | The |
5b2abdfb | 212 | .Fn dbm_error db |
59e0d9fe | 213 | function |
5b2abdfb A |
214 | returns the |
215 | .Va errno | |
216 | value of the most recent error. | |
59e0d9fe | 217 | The |
5b2abdfb | 218 | .Fn dbm_clearerr db |
59e0d9fe | 219 | function |
5b2abdfb A |
220 | resets this value to 0 and returns 0. |
221 | .Pp | |
59e0d9fe | 222 | The |
5b2abdfb | 223 | .Fn dbm_dirfno db |
59e0d9fe | 224 | function |
5b2abdfb A |
225 | returns the file descriptor to the database. |
226 | .Sh SEE ALSO | |
227 | .Xr open 2 , | |
228 | .Xr dbopen 3 , | |
229 | .Xr hash 3 | |
230 | .Sh STANDARDS | |
231 | These functions (except | |
232 | .Fn dbm_dirfno ) | |
233 | are included in the | |
234 | .St -susv2 . |