NDBM(3) 1990 NDBM(3) NNAAMMEE dbm_open, dbm_close, dbm_fetch, dbm_store, dbm_delete, dbm_firstkey, dbm_nextkey, dbm_error, dbm_clearerr - data base subroutines SSYYNNOOPPSSIISS ##iinncclluuddee <<nnddbbmm..hh>> ttyyppeeddeeff ssttrruucctt {{ cchhaarr **ddppttrr;; iinntt ddssiizzee;; }} ddaattuumm;; DDBBMM **ddbbmm__ooppeenn((ffiillee,, ffllaaggss,, mmooddee)) cchhaarr **ffiillee;; iinntt ffllaaggss,, mmooddee;; vvooiidd ddbbmm__cclloossee((ddbb)) DDBBMM **ddbb;; ddaattuumm ddbbmm__ffeettcchh((ddbb,, kkeeyy)) DDBBMM **ddbb;; ddaattuumm kkeeyy;; iinntt ddbbmm__ssttoorree((ddbb,, kkeeyy,, ccoonntteenntt,, ffllaaggss)) DDBBMM **ddbb;; ddaattuumm kkeeyy,, ccoonntteenntt;; iinntt ffllaaggss;; iinntt ddbbmm__ddeelleettee((ddbb,, kkeeyy)) DDBBMM **ddbb;; ddaattuumm kkeeyy;; ddaattuumm ddbbmm__ffiirrssttkkeeyy((ddbb)) DDBBMM **ddbb;; ddaattuumm ddbbmm__nneexxttkkeeyy((ddbb)) DDBBMM **ddbb;; iinntt ddbbmm__eerrrroorr((ddbb)) DDBBMM **ddbb;; iinntt ddbbmm__cclleeaarreerrrr((ddbb)) DDBBMM **ddbb;; DDEESSCCRRIIPPTTIIOONN These 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. This package replaces the earlier _d_b_m(3x) library, which managed only a single database. Printed 7/27/90 January 1 NDBM(3) 1990 NDBM(3) _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__o_p_e_n. This will open and/or create the files _f_i_l_e..ddiirr and _f_i_l_e..ppaagg depending on the flags parameter (see _o_p_e_n(2)). Once open, the data stored under a key is accessed by _d_b_m__f_e_t_c_h and data is placed under a key by _d_b_m__s_t_o_r_e. The _f_l_a_g_s field can be either DDBBMM__IINNSSEERRTT or DDBBMM__RREEPPLLAACCEE.. DDBBMM__IINNSSEERRTT will only insert new entries into the database and will not change an existing entry with the same key. DDBBMM__RREEPPLLAACCEE will replace an existing entry if it has the same key. A key (and its associated contents) is deleted by _d_b_m__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 _d_b_m__f_i_r_s_t_k_e_y and _d_b_m__n_e_x_t_k_e_y. _D_b_m__f_i_r_s_t_k_e_y will return the first key in the database. _D_b_m__n_e_x_t_k_e_y will return the next key in the database. This code will traverse the data base: ffoorr (key = dbm_firstkey(db); key.dptr != NULL; key = dbm_nextkey(db)) _D_b_m__e_r_r_o_r returns non-zero when an error has occurred read- ing or writing the database. _D_b_m__c_l_e_a_r_e_r_r resets the error condition on the named database. DDIIAAGGNNOOSSTTIICCSS All 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. If _d_b_m__s_t_o_r_e called with a _f_l_a_g_s value of DDBBMM__IINNSSEERRTT finds an existing entry with the same key it returns 1. BBUUGGSS 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. This storage is not necessarily aligned; stored ``longs'', for example, should be copied to a properly aligned block of memory before being accessed. Printed 7/27/90 January 2 NDBM(3) 1990 NDBM(3) 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. _D_b_m__s_t_o_r_e will return an error in the event that a disk block fills with inseparable data. _D_b_m__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 _d_b_m__f_i_r_s_t_k_e_y and _d_b_m__n_e_x_t_k_e_y depends on a hashing function, not on anything interesting. SSEEEE AALLSSOO dbm(3X) Printed 7/27/90 January 3