*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->OpenBSD man pages -> dbm_fetch (3)              



NAME    [Toc]    [Back]

     dbm_clearerr, dbm_close, dbm_delete, dbm_dirfno,  dbm_error,
     dbm_firstkey, dbm_nextkey, dbm_open, dbm_pagfno, dbm_store -
database access

SYNOPSIS    [Toc]    [Back]

     #include <ndbm.h>

     dbm_clearerr(DBM *db);

     dbm_close(DBM *db);

     dbm_delete(DBM *db, datum key);

     dbm_dirfno(DBM *db);

     dbm_error(DBM *db);

     dbm_fetch(DBM *db, datum key);

     dbm_firstkey(DBM *db);

     dbm_nextkey(DBM *db);

     DBM *
     dbm_open(const char *file, int flags, mode_t mode);

     dbm_pagfno(DBM *db);

     dbm_store(DBM   *db,   datum   key,   datum   content,   int

DESCRIPTION    [Toc]    [Back]

     These  functions  provide a ndbm-compatible interface to the
database access
 methods described in db(3).  Each unique record in  the
database is a
     key/content  pair,  the components of which may be any arbitrary binary data.
  The key and the content data are described by the datum
data structure:

           typedef struct {
                   void *dptr;
                   size_t dsize;
           } datum

     The  dbm_open()  function  is used to open a database in the
file named by
     file, suffixed with DBM_SUFFIX (`.db').  If  necessary,  the
file is created
 with mode mode.  Access to this file depends on the flags
     (see open(2)).  Read-only access may be indicated by  specifying

     Once  the  database is open, dbm_fetch() is used to retrieve
the data content
 associated with the key key.  Similarly, dbm_store() is
used to
     store  the content data with the key key.  When storing, the
     parameter must be one of:

           DBM_INSERT   Only insert new keys into  the  database.
                        key/content pairs are untouched.

           DBM_REPLACE   Replace any existing entry with the same
key.  Any
                        previously stored records with  the  same
key are lost.

     The  dbm_delete() function removes the key key and its associated content
     from the database.

     The functions dbm_firstkey() and dbm_nextkey() are  used  to
iterate over
     all  of  the  records  in the database.  Each record will be
reached exactly
     once, but in no particular order.  The dbm_firstkey()  function returns
     the   first   record   of   the   database,  and  thereafter
dbm_nextkey() returns
     the following records.  The following code traverses the entire database:

       for  (key  =  dbm_firstkey(db);  key.dptr  !=  NULL; key =

     The behaviour of dbm_nextkey() is undefined if the  database
is modified
     after a call to dbm_firstkey().

     The dbm_error() function returns the last error condition of
     database, or 0 if no error had occurred or had been cleared.
     dbm_clearerr()  function  clears  the error condition of the

     The dbm_dirfno() function is used to find the file  descriptor associated
     with the directory file of an open database.  Since a directory bitmap
     file is not used in this implementation, this  function  returns the file
     descriptor of the database file opened with dbm_open().

     The  dbm_pagfno() function is used to find the file descriptor associated
     with the page file of an open database.  Since a  page  file
is not used in
     this implementation, this function is implemented as a macro
that always
     returns the (undefined) value DBM_PAGFNO_NOT_AVAILABLE.

     The  database  is  closed  with  the  dbm_close()  function.
Thereafter, the db
     handle is invalid.

   Implementation notes    [Toc]    [Back]
     The  underlying database is a hash(3) database with a bucket
size of 4096,
     a filling factor of 40, default hashing function  and  cache
size, and uses
     the host's native byte order.

RETURN VALUES    [Toc]    [Back]

     Upon  successful  completion,  all functions that return int
return a value
     of 0, otherwise a negative value is returned.

     Routines that return a datum indicate errors by setting  the
dptr field to

     The  dbm_open()  function  returns  NULL  on error, and sets
errno appropriately.
  On success, it returns a handle to the database that
should be
     used as the db argument in the other functions.

     The  dbm_store() function returns 1 when it is called with a
flags value
     of DBM_INSERT and a record with the  specified  key  already

ERRORS    [Toc]    [Back]

     If  an  error  occurs,  the  error  can  be  retrieved  with
dbm_error() and corresponds
 to those errors described in db(3).

SEE ALSO    [Toc]    [Back]

     open(2), db(3), dbm(3), hash(3)

OpenBSD      3.6                           May      13,      1998
[ Back ]
 Similar pages
Name OS Title
dbm_error FreeBSD database access functions
dbm_fetch FreeBSD database access functions
dbm_firstkey FreeBSD database access functions
dbm_nextkey FreeBSD database access functions
dbm_open FreeBSD database access functions
dbm_store FreeBSD database access functions
dbm_clearerr FreeBSD database access functions
dbm_close FreeBSD database access functions
dbm_delete FreeBSD database access functions
dbm_dirnfo FreeBSD database access functions
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service