Debian Codegraph @

docs/api_reference/C/dbm.html

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <title>dbm/ndbm</title>
7 <link rel="stylesheet" href="apiReference.css" type="text/css" />
8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
9 <link rel="start" href="index.html" title="Berkeley DB C API Reference" />
10 <link rel="up" href="historic.html" title="Appendix B.  Historic Interfaces" />
11 <link rel="prev" href="historic.html" title="Appendix B.  Historic Interfaces" />
12 <link rel="next" href="hsearch.html" title="hsearch" />
13 </head>
14 <body>
15 <div xmlns="" class="navheader">
16 <div class="libver">
17 <p>Library Version 11.2.5.3</p>
18 </div>
19 <table width="100%" summary="Navigation header">
20 <tr>
21 <th colspan="3" align="center">dbm/ndbm</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="historic.html">Prev</a> </td>
25 <th width="60%" align="center">Appendix B. 
26 Historic Interfaces
27 </th>
28 <td width="20%" align="right"> <a accesskey="n" href="hsearch.html">Next</a></td>
29 </tr>
30 </table>
31 <hr />
32 </div>
33 <div class="sect1" lang="en" xml:lang="en">
34 <div class="titlepage">
35 <div>
36 <div>
37 <h2 class="title" style="clear: both"><a id="dbm"></a>dbm/ndbm</h2>
38 </div>
39 </div>
40 </div>
41 <pre class="programlisting">#define DB_DBM_HSEARCH 1
42 #include &lt;db.h&gt;
43
44 typedef struct {
45 char *dptr;
46 int dsize;
47 } datum; </pre>
48 <p>
49 <span class="bold"><strong>Dbm Functions</strong></span>
50 </p>
51 <pre class="programlisting">int
52 dbminit(char *file);
53
54 int
55 dbmclose();
56
57 datum
58 fetch(datum key);
59
60 int
61 store(datum key, datum content);
62
63 int
64 delete(datum key);
65
66 datum
67 firstkey(void);
68
69 datum
70 nextkey(datum key);</pre>
71 <p>
72 <span class="bold"><strong>Ndbm Functions</strong></span>
73 </p>
74 <pre class="programlisting">DBM *
75 dbm_open(char *file, int flags, int mode);
76
77 void
78 dbm_close(DBM *db);
79
80 datum
81 dbm_fetch(DBM *db, datum key);
82
83 int
84 dbm_store(DBM *db, datum key, datum content, int flags);
85
86 int
87 dbm_delete(DBM *db, datum key);
88
89 datum
90 dbm_firstkey(DBM *db);
91
92 datum
93 dbm_nextkey(DBM *db);
94
95 int
96 dbm_error(DBM *db);
97
98 int
99 dbm_clearerr(DBM *db); </pre>
100 <p>
101 The dbm functions are intended to provide high-performance
102 implementations and source code compatibility for applications written
103 to historic interfaces. They are not recommended for any other
104 purpose. The historic dbm database format <span class="bold"><strong>is not
105 supported</strong></span>, and databases previously built using the real
106 dbm libraries cannot be read by the Berkeley DB functions.
107 </p>
108 <p>
109 To compile dbm applications, replace the application's <span class="bold"><strong>#include</strong></span> of the dbm or ndbm include file (for
110 example, <span class="bold"><strong>#include &lt;dbm.h&gt;</strong></span> or
111 <span class="bold"><strong>#include &lt;ndbm.h&gt;</strong></span>) with the
112 following two lines:
113 </p>
114 <pre class="programlisting">#define DB_DBM_HSEARCH 1
115 #include &lt;db.h&gt;</pre>
116 <p>
117 and recompile. If the application attempts to load against a dbm
118 library (for example, <span class="bold"><strong>-ldbm</strong></span>), remove
119 the library from the load line.
120 </p>
121 <p>
122 <span class="bold"><strong>Key</strong></span> and
123 <span class="bold"><strong>content</strong></span> parameters are objects described by the
124 <span class="bold"><strong>datum</strong></span> typedef. A
125 <span class="bold"><strong>datum</strong></span> specifies a string of
126 <span class="bold"><strong>dsize</strong></span> bytes pointed to by
127 <span class="bold"><strong>dptr</strong></span>. Arbitrary binary data, as well as normal
128 text strings, are allowed.
129 </p>
130 <div class="sect2" lang="en" xml:lang="en">
131 <div class="titlepage">
132 <div>
133 <div>
134 <h3 class="title"><a id="dbmfunctions"></a>Dbm Functions</h3>
135 </div>
136 </div>
137 </div>
138 <p>
139 Before a database can be accessed, it must be opened by dbminit. This
140 will open and/or create the database
141 <span class="bold"><strong>file.db</strong></span>. If created, the database file is
142 created read/write by owner only (as described in
143 <span class="bold"><strong>chmod</strong></span>(2)) and modified by the process' umask
144 value at the time of creation (see
145 <span class="bold"><strong>umask</strong></span>(2)). The group ownership of created
146 files is based on the system and directory defaults, and is not
147 further specified by Berkeley DB.
148 </p>
149 <p>
150 A database may be closed, and any held resources released, by calling
151 dbmclose.
152 </p>
153 <p>
154 Once open, the data stored under a key is accessed by fetch, and data
155 is placed under a key by store. A key (and its associated contents)
156 are deleted by delete. A linear pass through all keys in a database
157 may be made, in an (apparently) random order, by using firstkey and
158 nextkey. The firstkey method will return the first key in the
159 databaseThe nextkey method will return the next key in satabase.
160 </p>
161 <p>
162 The following code will traverse the database:
163 </p>
164 <pre class="programlisting">for (key = firstkey(key);
165 key.dptr != NULL; key = nextkey(key)) {
166 ...
167 } </pre>
168 </div>
169 <div class="sect2" lang="en" xml:lang="en">
170 <div class="titlepage">
171 <div>
172 <div>
173 <h3 class="title"><a id="ndbmfunctions"></a>Ndbm Functions</h3>
174 </div>
175 </div>
176 </div>
177 <p>
178 Before a database can be accessed, it must be opened by dbm_open. This
179 will open and/or create the database file
180 <span class="bold"><strong>file.db</strong></span>, depending on the flags parameter (see
181 <span class="bold"><strong>open</strong></span>(2)). If created, the database
182 file is created with mode <span class="bold"><strong>mode</strong></span> (as
183 described in <span class="bold"><strong>chmod</strong></span>(2)) and modified
184 by the process' umask value at the time of creation (see <span class="bold"><strong>umask</strong></span>(2)). The group ownership of created
185 files is based on the system and directory defaults, and is not
186 further specified by Berkeley DB.
187 </p>
188 <p>
189 Once open, the data stored under a key is accessed by dbm_fetch, and
190 data is placed under a key by dbm_store. The
191 <span class="bold"><strong>flags</strong></span> field can be either
192 <span class="bold"><strong>DBM_INSERT</strong></span> or
193 <span class="bold"><strong>DBM_REPLACE</strong></span>.
194 <span class="bold"><strong>DBM_INSERT</strong></span> will only insert new entries into
195 the database, and will not change an existing entry with the same key.
196 <span class="bold"><strong>DBM_REPLACE</strong></span> will replace an existing
197 entry if it has the same key. A key (and its associated contents) are
198 deleted by dbm_delete. A linear pass through all keys in a database
199 may be made, in an (apparently) random order, by using dbm_firstkey
200 and dbm_nextkey. The dbm_firstkey method will return the first key in
201 the database. The dbm_nextkey method will return the next key in the
202 database.
203 </p>
204 <p>
205 The following code will traverse the database:
206 </p>
207 <pre class="programlisting">for (key = dbm_firstkey(db);
208 key.dptr != NULL; key = dbm_nextkey(db)) {
209 ...
210 } </pre>
211 </div>
212 <div class="sect2" lang="en" xml:lang="en">
213 <div class="titlepage">
214 <div>
215 <div>
216 <h3 class="title"><a id="dbm_compat_notes"></a>Compatibility Notes</h3>
217 </div>
218 </div>
219 </div>
220 <p>
221 The historic dbm library created two underlying database files,
222 traditionally named <span class="bold"><strong>file.dir</strong></span> and
223 <span class="bold"><strong>file.pag</strong></span>. The Berkeley DB library
224 creates a single database file named <span class="bold"><strong>file.db</strong></span>. Applications that are aware of the
225 underlying database filenames may require additional source code
226 modifications.
227 </p>
228 <p>
229 The historic dbminit function required that the underlying <span class="bold"><strong>.dir</strong></span> and <span class="bold"><strong>.pag</strong></span>
230 files already exist (empty databases were created by first manually
231 creating zero-length <span class="bold"><strong>.dir</strong></span> and
232 <span class="bold"><strong>.pag</strong></span> files). Applications that
233 expect to create databases using this method may require additional
234 source code modifications.
235 </p>
236 <p>
237 The historic dbm_dirfno and dbm_pagfno macros are supported, but will
238 return identical file descriptors because there is only a single
239 underlying file used by the Berkeley DB hashing access method.
240 Applications using both file descriptors for locking may require
241 additional source code modifications.
242 </p>
243 <p>
244 If applications using the dbm function exits without first closing the
245 database, it may lose updates because the Berkeley DB library buffers
246 writes to underlying databases. Such applications will require
247 additional source code modifications to work correctly with the
248 Berkeley DB library.
249 </p>
250 </div>
251 <div class="sect2" lang="en" xml:lang="en">
252 <div class="titlepage">
253 <div>
254 <div>
255 <h3 class="title"><a id="dbm_diagnostics"></a>Dbm Diagnostics</h3>
256 </div>
257 </div>
258 </div>
259 <p>
260 The dbminit function returns -1 on failure, setting <span class="bold"><strong>errno</strong></span>, and 0 on success.
261 </p>
262 <p>
263 The fetch function sets the <span class="bold"><strong>dptr</strong></span>
264 field of the returned <span class="bold"><strong>datum</strong></span> to NULL
265 on failure, setting <span class="bold"><strong>errno</strong></span>, and
266 returns a non-NULL <span class="bold"><strong>dptr</strong></span> on success.
267 </p>
268 <p>
269 The store function returns -1 on failure, setting <span class="bold"><strong>errno</strong></span>, and 0 on success.
270 </p>
271 <p>
272 The delete function returns -1 on failure, setting <span class="bold"><strong>errno</strong></span>, and 0 on success.
273 </p>
274 <p>
275 The firstkey function sets the <span class="bold"><strong>dptr</strong></span>
276 field of the returned <span class="bold"><strong>datum</strong></span> to NULL
277 on failure, setting <span class="bold"><strong>errno</strong></span>, and
278 returns a non-NULL <span class="bold"><strong>dptr</strong></span> on success.
279 </p>
280 <p>
281 The nextkey function sets the <span class="bold"><strong>dptr</strong></span>
282 field of the returned <span class="bold"><strong>datum</strong></span> to NULL
283 on failure, setting <span class="bold"><strong>errno</strong></span>, and
284 returns a non-NULL <span class="bold"><strong>dptr</strong></span> on success.
285 </p>
286 </div>
287 <div class="sect2" lang="en" xml:lang="en">
288 <div class="titlepage">
289 <div>
290 <div>
291 <h3 class="title"><a id="dbm_errors"></a>Dbm Errors</h3>
292 </div>
293 </div>
294 </div>
295 <p>
296 The dbminit, fetch, store, delete, firstkey, and nextkey functions may
297 fail and return an error for errors specified for other Berkeley DB
298 and C library or system functions.
299 </p>
300 </div>
301 <div class="sect2" lang="en" xml:lang="en">
302 <div class="titlepage">
303 <div>
304 <div>
305 <h3 class="title"><a id="ndbm_diagnostics"></a>Ndbm Diagnostics</h3>
306 </div>
307 </div>
308 </div>
309 <p>
310 The dbm_close method returns non-zero when an error has occurred
311 reading or writing the database.
312 </p>
313 <p>
314 The dbm_close method resets the error condition on the named database.
315 </p>
316 <p>
317 The dbm_open function returns NULL on failure, setting <span class="bold"><strong>errno</strong></span>, and a DBM reference on success.
318 </p>
319 <p>
320 The dbm_fetch function sets the <span class="bold"><strong>dptr</strong></span>
321 field of the returned <span class="bold"><strong>datum</strong></span> to NULL
322 on failure, setting <span class="bold"><strong>errno</strong></span>, and
323 returns a non-NULL <span class="bold"><strong>dptr</strong></span> on success.
324 </p>
325 <p>
326 The dbm_store function returns -1 on failure, setting <span class="bold"><strong>errno</strong></span>, 0 on success, and 1 if DBM_INSERT was
327 set and the specified key already existed in the database.
328 </p>
329 <p>
330 The dbm_delete function returns -1 on failure, setting <span class="bold"><strong>errno</strong></span>, and 0 on success.
331 </p>
332 <p>
333 The dbm_firstkey function sets the <span class="bold"><strong>dptr</strong></span> field of the returned <span class="bold"><strong>datum</strong></span> to NULL on failure, setting <span class="bold"><strong>errno</strong></span>, and returns a non-NULL <span class="bold"><strong>dptr</strong></span> on success.
334 </p>
335 <p>
336 The dbm_nextkey function sets the <span class="bold"><strong>dptr</strong></span> field of the returned <span class="bold"><strong>datum</strong></span> to NULL on failure, setting <span class="bold"><strong>errno</strong></span>, and returns a non-NULL <span class="bold"><strong>dptr</strong></span> on success.
337 </p>
338 <p>
339 The dbm_close function returns -1 on failure, setting <span class="bold"><strong>errno</strong></span>, and 0 on success.
340 </p>
341 <p>
342 The dbm_close function returns -1 on failure, setting <span class="bold"><strong>errno</strong></span>, and 0 on success.
343 </p>
344 </div>
345 <div class="sect2" lang="en" xml:lang="en">
346 <div class="titlepage">
347 <div>
348 <div>
349 <h3 class="title"><a id="ndbm_errors"></a>Ndbm Errors</h3>
350 </div>
351 </div>
352 </div>
353 <p>
354 The dbm_open, dbm_close, dbm_fetch, dbm_store, dbm_delete,
355 dbm_firstkey, and dbm_nextkey functions may fail and return an error
356 for errors specified for other Berkeley DB and C library or system
357 functions.
358 </p>
359 </div>
360 </div>
361 <div class="navfooter">
362 <hr />
363 <table width="100%" summary="Navigation footer">
364 <tr>
365 <td width="40%" align="left"><a accesskey="p" href="historic.html">Prev</a> </td>
366 <td width="20%" align="center">
367 <a accesskey="u" href="historic.html">Up</a>
368 </td>
369 <td width="40%" align="right"> <a accesskey="n" href="hsearch.html">Next</a></td>
370 </tr>
371 <tr>
372 <td width="40%" align="left" valign="top">Appendix B. 
373 Historic Interfaces
374  </td>
375 <td width="20%" align="center">
376 <a accesskey="h" href="index.html">Home</a>
377 </td>
378 <td width="40%" align="right" valign="top"> hsearch</td>
379 </tr>
380 </table>
381 </div>
382 </body>
383 </html>