1DBM_CLEARERR(3P) POSIX Programmer's Manual DBM_CLEARERR(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 dbm_clearerr, dbm_close, dbm_delete, dbm_error, dbm_fetch,
13 dbm_firstkey, dbm_nextkey, dbm_open, dbm_store — database functions
14
16 #include <ndbm.h>
17
18 int dbm_clearerr(DBM *db);
19 void dbm_close(DBM *db);
20 int dbm_delete(DBM *db, datum key);
21 int dbm_error(DBM *db);
22 datum dbm_fetch(DBM *db, datum key);
23 datum dbm_firstkey(DBM *db);
24 datum dbm_nextkey(DBM *db);
25 DBM *dbm_open(const char *file, int open_flags, mode_t file_mode);
26 int dbm_store(DBM *db, datum key, datum content, int store_mode);
27
29 These functions create, access, and modify a database.
30
31 A datum consists of at least two members, dptr and dsize. The dptr
32 member points to an object that is dsize bytes in length. Arbitrary
33 binary data, as well as character strings, may be stored in the object
34 pointed to by dptr.
35
36 A database shall be stored in one or two files. When one file is used,
37 the name of the database file shall be formed by appending the suffix
38 .db to the file argument given to dbm_open(). When two files are used,
39 the names of the database files shall be formed by appending the suf‐
40 fixes .dir and .pag respectively to the file argument.
41
42 The dbm_open() function shall open a database. The file argument to the
43 function is the pathname of the database. The open_flags argument has
44 the same meaning as the flags argument of open() except that a database
45 opened for write-only access opens the files for read and write access
46 and the behavior of the O_APPEND flag is unspecified. The file_mode
47 argument has the same meaning as the third argument of open().
48
49 The dbm_open() function need not accept pathnames longer than
50 {PATH_MAX}-4 bytes (including the terminating null), or pathnames with
51 a last component longer than {NAME_MAX}-4 bytes (excluding the termi‐
52 nating null).
53
54 The dbm_close() function shall close a database. The application shall
55 ensure that argument db is a pointer to a dbm structure that has been
56 returned from a call to dbm_open().
57
58 These database functions shall support an internal block size large
59 enough to support key/content pairs of at least 1023 bytes.
60
61 The dbm_fetch() function shall read a record from a database. The argu‐
62 ment db is a pointer to a database structure that has been returned
63 from a call to dbm_open(). The argument key is a datum that has been
64 initialized by the application to the value of the key that matches the
65 key of the record the program is fetching.
66
67 The dbm_store() function shall write a record to a database. The argu‐
68 ment db is a pointer to a database structure that has been returned
69 from a call to dbm_open(). The argument key is a datum that has been
70 initialized by the application to the value of the key that identifies
71 (for subsequent reading, writing, or deleting) the record the applica‐
72 tion is writing. The argument content is a datum that has been initial‐
73 ized by the application to the value of the record the program is writ‐
74 ing. The argument store_mode controls whether dbm_store() replaces any
75 pre-existing record that has the same key that is specified by the key
76 argument. The application shall set store_mode to either DBM_INSERT or
77 DBM_REPLACE. If the database contains a record that matches the key
78 argument and store_mode is DBM_REPLACE, the existing record shall be
79 replaced with the new record. If the database contains a record that
80 matches the key argument and store_mode is DBM_INSERT, the existing
81 record shall be left unchanged and the new record ignored. If the data‐
82 base does not contain a record that matches the key argument and
83 store_mode is either DBM_INSERT or DBM_REPLACE, the new record shall be
84 inserted in the database.
85
86 If the sum of a key/content pair exceeds the internal block size, the
87 result is unspecified. Moreover, the application shall ensure that all
88 key/content pairs that hash together fit on a single block. The
89 dbm_store() function shall return an error in the event that a disk
90 block fills with inseparable data.
91
92 The dbm_delete() function shall delete a record and its key from the
93 database. The argument db is a pointer to a database structure that has
94 been returned from a call to dbm_open(). The argument key is a datum
95 that has been initialized by the application to the value of the key
96 that identifies the record the program is deleting.
97
98 The dbm_firstkey() function shall return the first key in the database.
99 The argument db is a pointer to a database structure that has been
100 returned from a call to dbm_open().
101
102 The dbm_nextkey() function shall return the next key in the database.
103 The argument db is a pointer to a database structure that has been
104 returned from a call to dbm_open(). The application shall ensure that
105 the dbm_firstkey() function is called before calling dbm_nextkey().
106 Subsequent calls to dbm_nextkey() return the next key until all of the
107 keys in the database have been returned.
108
109 The dbm_error() function shall return the error condition of the data‐
110 base. The argument db is a pointer to a database structure that has
111 been returned from a call to dbm_open().
112
113 The dbm_clearerr() function shall clear the error condition of the
114 database. The argument db is a pointer to a database structure that has
115 been returned from a call to dbm_open().
116
117 The dptr pointers returned by these functions may point into static
118 storage that may be changed by subsequent calls.
119
120 These functions need not be thread-safe.
121
123 The dbm_store() and dbm_delete() functions shall return 0 when they
124 succeed and a negative value when they fail.
125
126 The dbm_store() function shall return 1 if it is called with a flags
127 value of DBM_INSERT and the function finds an existing record with the
128 same key.
129
130 The dbm_error() function shall return 0 if the error condition is not
131 set and return a non-zero value if the error condition is set.
132
133 The return value of dbm_clearerr() is unspecified.
134
135 The dbm_firstkey() and dbm_nextkey() functions shall return a key
136 datum. When the end of the database is reached, the dptr member of the
137 key is a null pointer. If an error is detected, the dptr member of the
138 key shall be a null pointer and the error condition of the database
139 shall be set.
140
141 The dbm_fetch() function shall return a content datum. If no record in
142 the database matches the key or if an error condition has been detected
143 in the database, the dptr member of the content shall be a null
144 pointer.
145
146 The dbm_open() function shall return a pointer to a database structure.
147 If an error is detected during the operation, dbm_open() shall return a
148 (DBM *)0.
149
151 No errors are defined.
152
153 The following sections are informative.
154
156 None.
157
159 The following code can be used to traverse the database:
160
161
162 for(key = dbm_firstkey(db); key.dptr != NULL; key = dbm_nextkey(db))
163
164 The dbm_* functions provided in this library should not be confused in
165 any way with those of a general-purpose database management system.
166 These functions do not provide for multiple search keys per entry, they
167 do not protect against multi-user access (in other words they do not
168 lock records or files), and they do not provide the many other useful
169 database functions that are found in more robust database management
170 systems. Creating and updating databases by use of these functions is
171 relatively slow because of data copies that occur upon hash collisions.
172 These functions are useful for applications requiring fast lookup of
173 relatively static information that is to be indexed by a single key.
174
175 Note that a strictly conforming application is extremely limited by
176 these functions: since there is no way to determine that the keys in
177 use do not all hash to the same value (although that would be rare), a
178 strictly conforming application cannot be guaranteed that it can store
179 more than one block's worth of data in the database. As long as a key
180 collision does not occur, additional data may be stored, but because
181 there is no way to determine whether an error is due to a key collision
182 or some other error condition (dbm_error() being effectively a Bool‐
183 ean), once an error is detected, the application is effectively limited
184 to guessing what the error might be if it wishes to continue using
185 these functions.
186
187 The dbm_delete() function need not physically reclaim file space,
188 although it does make it available for reuse by the database.
189
190 After calling dbm_store() or dbm_delete() during a pass through the
191 keys by dbm_firstkey() and dbm_nextkey(), the application should reset
192 the database by calling dbm_firstkey() before again calling dbm_nex‐
193 tkey(). The contents of these files are unspecified and may not be
194 portable.
195
196 Applications should take care that database pathname arguments speci‐
197 fied to dbm_open() are not prefixes of unrelated files. This might be
198 done, for example, by placing databases in a separate directory.
199
200 Since some implementations use three characters for a suffix and others
201 use four characters for a suffix, applications should ensure that the
202 maximum portable pathname length passed to dbm_open() is no greater
203 than {PATH_MAX}-4 bytes, with the last component of the pathname no
204 greater than {NAME_MAX}-4 bytes.
205
207 Previously the standard required the database to be stored in two
208 files, one file being a directory containing a bitmap of keys and hav‐
209 ing .dir as its suffix. The second file containing all data and having
210 .pag as its suffix. This has been changed not to specify the use of the
211 files and to allow newer implementations of the Berkeley DB interface
212 using a single file that have evolved while remaining compatible with
213 the application programming interface. The standard developers consid‐
214 ered removing the specific suffixes altogether but decided to retain
215 them so as not to pollute the application file name space more than
216 necessary and to allow for portable backups of the database.
217
219 None.
220
222 open()
223
224 The Base Definitions volume of POSIX.1‐2017, <ndbm.h>
225
227 Portions of this text are reprinted and reproduced in electronic form
228 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
229 table Operating System Interface (POSIX), The Open Group Base Specifi‐
230 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
231 Electrical and Electronics Engineers, Inc and The Open Group. In the
232 event of any discrepancy between this version and the original IEEE and
233 The Open Group Standard, the original IEEE and The Open Group Standard
234 is the referee document. The original Standard can be obtained online
235 at http://www.opengroup.org/unix/online.html .
236
237 Any typographical or formatting errors that appear in this page are
238 most likely to have been introduced during the conversion of the source
239 files to man page format. To report such errors, see https://www.ker‐
240 nel.org/doc/man-pages/reporting_bugs.html .
241
242
243
244IEEE/The Open Group 2017 DBM_CLEARERR(3P)