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

PROLOG

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

NAME

12       dbm_clearerr,    dbm_close,    dbm_delete,    dbm_error,     dbm_fetch,
13       dbm_firstkey, dbm_nextkey, dbm_open, dbm_store - database functions
14

SYNOPSIS

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
28

DESCRIPTION

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

RETURN VALUE

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

ERRORS

147       No errors are defined.
148
149       The following sections are informative.
150

EXAMPLES

152       None.
153

APPLICATION USAGE

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

RATIONALE

193       None.
194

FUTURE DIRECTIONS

196       None.
197

SEE ALSO

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