[0m


DBM(3X)             UNIX Programmer's Manual		  DBM(3X)



[1mNAME
     [0mdbminit, fetch, store, delete, firstkey, nextkey - data base
     subroutines

[1mSYNOPSIS
     #include <dbm.h>

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

     dbminit(file)
     char *file;

     dbmclose()

     datum fetch(key)
     datum key;

     store(key, content)
     datum key, content;

     delete(key)
     datum key;

     datum firstkey()

     datum nextkey(key)
     datum key;

DESCRIPTION
     Note: the dbm library has been superceded by ndbm(3), and is
     now implemented using ndbm.  [0mThese functions maintain
     key/content pairs in a data base.	The functions will handle
     very large (a billion blocks) databases and will access a
     keyed item in one or two file system accesses.  The func-
     tions are obtained with the loader option [1m-ldbm[0m.

     _K_e_ys and _c_o_n_t_e_n_ts are described by the _d_a_t_u_m typedef.  A
     _d_a_t_u_m specifies a string of _d_s_i_z_e bytes pointed to by _d_p_t_r.
     Arbitrary binary data, as well as normal ASCII strings, are
     allowed.  The data base is stored in two files.  One file is
     a directory containing a bit map and has `.dir' as its suf-
     fix.  The second file contains all data and has `.pag' as
     its suffix.

     Before a database can be accessed, it must be opened by
     _d_b_m_i_n_i_t. At the time of this call, the files _f_i_l_e[1m.dir [0mand
     _f_i_l_e[1m.pag [0mmust exist.  (An empty database is created by
     creating zero-length `.dir' and `.pag' files.)




Printed 18/11/94    Revision 1.4 of 01/07/90			1






DBM(3X)             UNIX Programmer's Manual		  DBM(3X)



     A database may be closed by calling dbmclose.  You must
     close a database before opening a new one.

     Once open, the data stored under a key is accessed by _f_e_t_c_h
     and data is placed under a key by _s_t_o_r_e.  A key (and its
     associated contents) is deleted by _d_e_l_e_t_e.  A linear pass
     through all keys in a database may be made, in an
     (apparently) random order, by use of _f_i_r_s_t_k_e_y and _n_e_x_t_k_e_y.
     _F_i_r_s_t_k_e_y will return the first key in the database.  With
     any key _n_e_x_t_k_e_y will return the next key in the database.
     This code will traverse the data base:

	  [1mfor [0m(key = firstkey(); key.dptr != NULL; key =
	  nextkey(key))

[1mDIAGNOSTICS
     [0mAll functions that return an _i_n_t indicate errors with nega-
     tive values.  A zero return indicates ok.	Routines that
     return a _d_a_t_u_m indicate errors with a null (0) _d_p_t_r.

[1mSEE ALSO
     [0mndbm(3)

[1mBUGS
     [0mThe data pointers returned by _d_b_m are char aligned, hence
     the data will need copying before it can be accessed as a
     structure.

     The `.pag' file will contain holes so that its apparent size
     is about four times its actual content.  Older UNIX systems
     may create real file blocks for these holes when touched.
     These files cannot be copied by normal means (cp, cat, tp,
     tar, ar) without filling in the holes.

     _D_p_t_r pointers returned by these subroutines point into
     static storage that is changed by subsequent calls.

     The sum of the sizes of a key/content pair must not exceed
     the internal block size (currently 1024 bytes).  Moreover
     all key/content pairs that hash together must fit on a sin-
     gle block.  _S_t_o_r_e will return an error in the event that a
     disk block fills with inseparable data.

     _D_e_l_e_t_e does not physically reclaim file space, although it
     does make it available for reuse.

     The order of keys presented by _f_i_r_s_t_k_e_y and _n_e_x_t_k_e_y depends
     on a hashing function, not on anything interesting.







Printed 18/11/94    Revision 1.4 of 01/07/90			2



[0m