Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
DBM(3)			 BSD Library Functions Manual			DBM(3)

NAME
     dbm_clearerr, dbm_close, dbm_delete, dbm_dirfno, dbm_error, dbm_fetch,
     dbm_firstkey, dbm_nextkey,	dbm_open, dbm_store -- database	access func-
     tions

SYNOPSIS
     #include <fcntl.h>
     #include <ndbm.h>

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

     void
     dbm_close(DBM *db);

     int
     dbm_store(DBM *db,	datum key, datum data, int flags);

     datum
     dbm_fetch(DBM *db,	datum key);

     int
     dbm_delete(DBM *db, datum key);

     datum
     dbm_firstkey(DBM *db);

     datum
     dbm_nextkey(DBM *db);

     int
     dbm_error(DBM *db);

     int
     dbm_clearerr(DBM *db);

     int
     dbm_dirfno(DBM *db);

DESCRIPTION
     Database access functions.	 These functions are implemented using
     dbopen(3) with a hash(3) database.

     datum is declared in <ndbm.h>:

     typedef struct {
	     char *dptr;
	     int dsize;
     } datum;

     dbm_open(base, flags, mode) opens or creates a database.  base is the
     basename of the file containing the database; the actual database has a
     .db suffix.  I.e.,	if base	is "/home/me/mystuff" then the actual database
     is	in the file /home/me/mystuff.db.  flags	and mode are passed to
     open(2).  (O_RDWR | O_CREAT) is a typical value for flags;	0660 is	a typ-
     ical value	for mode.  O_WRONLY is not allowed in flags.  The pointer re-
     turned by dbm_open() identifies the database and is the db	argument to
     the other functions.  dbm_open() returns NULL and sets errno if there
     were any errors.

     dbm_close(db) closes the database.	 dbm_close() normally returns zero.

     dbm_store(db, key,	data, flags) inserts or	replaces an entry in the data-
     base.  flags is either DBM_INSERT or DBM_REPLACE.	If flags is DBM_INSERT
     and the database already contains an entry	for key, that entry is not re-
     placed.  Otherwise	the entry is replaced or inserted.  dbm_store()	nor-
     mally returns zero	but returns 1 if the entry could not be	inserted (be-
     cause flags is DBM_INSERT,	and an entry with key already exists) or re-
     turns -1 and sets errno if	there were any errors.

     dbm_fetch(db, key)	returns	NULL or	the data corresponding to key.

     dbm_delete(db, key) deletes the entry for key.  dbm_delete() normally re-
     turns zero	but returns 1 if there was no entry with key in	the database
     or	returns	-1 and sets errno if there were	any errors.

     dbm_firstkey(db) returns the first	key in the database.  dbm_nextkey(db)
     returns subsequent	keys.  db_firstkey() must be called before
     dbm_nextkey().  The order in which	keys are returned is unspecified and
     may appear	random.	 dbm_nextkey() returns NULL after all keys have	been
     returned.

     dbm_error(db) returns the errno value of the most recent error.
     dbm_clearerr(db) resets this value	to 0 and returns 0.

     dbm_dirfno(db) returns the	file descriptor	to the database.

SEE ALSO
     open(2), dbopen(3), hash(3)

STANDARDS
     These functions (except dbm_dirfno()) are included	in the Version 2 of
     the Single	UNIX Specification ("SUSv2").

BSD				 July 7, 1999				   BSD

NAME | SYNOPSIS | DESCRIPTION | SEE ALSO | STANDARDS

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=dbm&sektion=3&manpath=FreeBSD+4.6-RELEASE>

home | help