1DBM_CLEARERR(P)            POSIX Programmer's Manual           DBM_CLEARERR(P)
2
3
4

NAME

6       dbm_clearerr,     dbm_close,    dbm_delete,    dbm_error,    dbm_fetch,
7       dbm_firstkey, dbm_nextkey, dbm_open, dbm_store - database functions
8

SYNOPSIS

10       #include <ndbm.h>
11
12       int dbm_clearerr(DBM *db);
13       void dbm_close(DBM *db);
14       int dbm_delete(DBM *db, datum key);
15       int dbm_error(DBM *db);
16       datum dbm_fetch(DBM *db, datum key);
17       datum dbm_firstkey(DBM *db);
18       datum dbm_nextkey(DBM *db);
19       DBM *dbm_open(const char *file, int open_flags, mode_t file_mode);
20       int dbm_store(DBM *db, datum key, datum content, int store_mode);
21
22

DESCRIPTION

24       These functions create, access, and modify a database.
25
26       A datum consists of at least two members, dptr  and  dsize.   The  dptr
27       member  points  to  an  object that is dsize bytes in length. Arbitrary
28       binary data, as well as character strings, may be stored in the  object
29       pointed to by dptr.
30
31       The database is stored in two files. One file is a directory containing
32       a bitmap of keys and has .dir as its suffix. The second  file  contains
33       all data and has .pag as its suffix.
34
35       The dbm_open() function shall open a database. The file argument to the
36       function is the pathname of the database.  The function opens two files
37       named  file.dir  and  file.pag.   The  open_flags argument has the same
38       meaning as the flags argument of open() except that a  database  opened
39       for write-only access opens the files for read and write access and the
40       behavior of the O_APPEND flag is unspecified.  The  file_mode  argument
41       has the same meaning as the third argument of open().
42
43       The  dbm_close() function shall close a database. The application shall
44       ensure that argument db is a pointer to a dbm structure that  has  been
45       returned from a call to dbm_open().
46
47       These  database  functions  shall  support an internal block size large
48       enough to support key/content pairs of at least 1023 bytes.
49
50       The dbm_fetch() function shall read a  record  from  a  database.   The
51       argument db is a pointer to a database structure that has been returned
52       from a call to dbm_open(). The argument key is a datum  that  has  been
53       initialized by the application to the value of the key that matches the
54       key of the record the program is fetching.
55
56       The dbm_store() function shall write a record to a database.  The argu‐
57       ment  db  is  a  pointer to a database structure that has been returned
58       from a call to dbm_open(). The argument key is a datum  that  has  been
59       initialized  by the application to the value of the key that identifies
60       (for subsequent reading, writing, or deleting) the record the  applica‐
61       tion is writing. The argument content is a datum that has been initial‐
62       ized by the application to the value of the record the program is writ‐
63       ing.  The argument store_mode controls whether dbm_store() replaces any
64       pre-existing record that has the same key that is specified by the  key
65       argument.  The application shall set store_mode to either DBM_INSERT or
66       DBM_REPLACE. If the database contains a record  that  matches  the  key
67       argument  and  store_mode  is DBM_REPLACE, the existing record shall be
68       replaced with the new record. If the database contains  a  record  that
69       matches  the  key  argument  and store_mode is DBM_INSERT, the existing
70       record shall be left unchanged and the new record ignored. If the data‐
71       base  does  not  contain  a  record  that  matches the key argument and
72       store_mode is either DBM_INSERT or DBM_REPLACE, the new record shall be
73       inserted in the database.
74
75       If  the  sum of a key/content pair exceeds the internal block size, the
76       result is unspecified. Moreover, the application shall ensure that  all
77       key/content  pairs  that  hash  together  fit  on  a  single block. The
78       dbm_store() function shall return an error in the  event  that  a  disk
79       block fills with inseparable data.
80
81       The  dbm_delete()  function  shall delete a record and its key from the
82       database. The argument db is a pointer to a database structure that has
83       been  returned  from a call to dbm_open().  The argument key is a datum
84       that has been initialized by the application to the value  of  the  key
85       that identifies the record the program is deleting.
86
87       The dbm_firstkey() function shall return the first key in the database.
88       The argument db is a pointer to a  database  structure  that  has  been
89       returned from a call to dbm_open().
90
91       The  dbm_nextkey()  function shall return the next key in the database.
92       The argument db is a pointer to a  database  structure  that  has  been
93       returned  from a call to dbm_open().  The application shall ensure that
94       the dbm_firstkey() function is  called  before  calling  dbm_nextkey().
95       Subsequent  calls to dbm_nextkey() return the next key until all of the
96       keys in the database have been returned.
97
98       The dbm_error() function shall return the error condition of the  data‐
99       base.  The  argument  db  is a pointer to a database structure that has
100       been returned from a call to dbm_open().
101
102       The dbm_clearerr() function shall clear  the  error  condition  of  the
103       database. The argument db is a pointer to a database structure that has
104       been returned from a call to dbm_open().
105
106       The dptr pointers returned by these functions  may  point  into  static
107       storage that may be changed by subsequent calls.
108
109       These  functions need not be reentrant. A function that is not required
110       to be reentrant is not required to be thread-safe.
111

RETURN VALUE

113       The dbm_store() and dbm_delete() functions shall  return  0  when  they
114       succeed and a negative value when they fail.
115
116       The  dbm_store()  function  shall return 1 if it is called with a flags
117       value of DBM_INSERT and the function finds an existing record with  the
118       same key.
119
120       The  dbm_error()  function shall return 0 if the error condition is not
121       set and return a non-zero value if the error condition is set.
122
123       The return value of dbm_clearerr() is unspecified.
124
125       The dbm_firstkey() and  dbm_nextkey()  functions  shall  return  a  key
126       datum.  When the end of the database is reached, the dptr member of the
127       key is a null pointer. If an error is detected, the dptr member of  the
128       key  shall  be  a  null pointer and the error condition of the database
129       shall be set.
130
131       The dbm_fetch() function shall return a content datum.  If no record in
132       the database matches the key or if an error condition has been detected
133       in the database, the dptr  member  of  the  content  shall  be  a  null
134       pointer.
135
136       The dbm_open() function shall return a pointer to a database structure.
137       If an error is detected during the operation, dbm_open() shall return a
138       ( DBM *)0.
139

ERRORS

141       No errors are defined.
142
143       The following sections are informative.
144

EXAMPLES

146       None.
147

APPLICATION USAGE

149       The following code can be used to traverse the database:
150
151
152              for(key = dbm_firstkey(db); key.dptr != NULL; key = dbm_nextkey(db))
153
154       The  dbm_* functions provided in this library should not be confused in
155       any way with those of a  general-purpose  database  management  system.
156       These functions do not provide for multiple search keys per entry, they
157       do not protect against multi-user access (in other words  they  do  not
158       lock  records  or files), and they do not provide the many other useful
159       database functions that are found in more  robust  database  management
160       systems.  Creating  and updating databases by use of these functions is
161       relatively slow because of data copies that occur upon hash collisions.
162       These  functions  are  useful for applications requiring fast lookup of
163       relatively static information that is to be indexed by a single key.
164
165       Note that a strictly conforming application  is  extremely  limited  by
166       these  functions:  since  there is no way to determine that the keys in
167       use do not all hash to the same value (although that would be rare),  a
168       strictly  conforming application cannot be guaranteed that it can store
169       more than one block's worth of data in the database.  As long as a  key
170       collision  does  not  occur, additional data may be stored, but because
171       there is no way to determine whether an error is due to a key collision
172       or  some  other error condition ( dbm_error() being effectively a Bool‐
173       ean), once an error is detected, the application is effectively limited
174       to  guessing  what  the  error  might be if it wishes to continue using
175       these functions.
176
177       The dbm_delete() function  need  not  physically  reclaim  file  space,
178       although it does make it available for reuse by the database.
179
180       After  calling  dbm_store()  or  dbm_delete() during a pass through the
181       keys by dbm_firstkey() and dbm_nextkey(), the application should  reset
182       the  database  by  calling dbm_firstkey() before again calling dbm_nex‐
183       tkey(). The contents of these files are unspecified and may not be por‐
184       table.
185

RATIONALE

187       None.
188

FUTURE DIRECTIONS

190       None.
191

SEE ALSO

193       open() , the Base Definitions volume of IEEE Std 1003.1-2001, <ndbm.h>
194
196       Portions  of  this text are reprinted and reproduced in electronic form
197       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
198       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
199       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
200       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
201       event of any discrepancy between this version and the original IEEE and
202       The  Open Group Standard, the original IEEE and The Open Group Standard
203       is the referee document. The original Standard can be  obtained  online
204       at http://www.opengroup.org/unix/online.html .
205
206
207
208IEEE/The Open Group                  2003                      DBM_CLEARERR(P)
Impressum