NDBM(3x,L) AIX Technical Reference NDBM(3x,L) ------------------------------------------------------------------------------- ndbm: dbm_open, dbm_close, dbm_fetch, dbm_store, dbm_firstkey, dbm_nextkey, dbm_forder PURPOSE Performs data base operations. LIBRARY Standard C Library (libc.a) SYNTAX #include typedef struct { char *dptr; int dsize; } datum DBM *dbm_open (file, flags, mode) int dbm_delete (db, key) char *file; DBM *db; int flags, mode; datum key; void dbm_close (db) datum dbm_firstkey (db) DBM *db; DBM *db; datum dbm_fetch (db, key) datum dbm_nextkey (db) DBM *db; DBM *db; datum key; int dbm_store (db, key, dat, replace) int dbm_forder (db, key) DBM *db; DBM *db; datum key, dat; datum key; int replace; DESCRIPTION Note: These subroutines are provided for BSD compatability. The ndbm subroutines maintain a data base of key-content pairs. These subroutines can handle very large data bases and access keyed items in one or two file system accesses. The key and the dat parameters are described by the typedef datum structure. The datum structure refers to a string of bytes, the length of which is specified by the dsize field. The string is pointed to by the dptr field. The dptr pointers returned by these subroutines point to static storage Processed October 11, 1991 NDBM(3x,L) 1 NDBM(3x,L) AIX Technical Reference NDBM(3x,L) that changes with subsequent calls. The strings can contain binary data or normal ASCII characters. The data base is stored in two files. One file is a directory that contains a bit map and is suffixed with .dir. The second file contains all data and is suffixed with .pag. The .pag file contains holes that increase its apparent size to about four times its actual size. You cannot copy a .pag file using the standard utilities such as cp and cat without first filling these holes. Before you can access a data base, you must open the data base with dbm_open. This will open and/or create the files file.dir and file.pag depending on the flags parameter (see open on page ...). After the data base is opened, you can use the fetch subroutine to access the data that is pointed to by the key parameter. You can use the store subroutine to write the data specified by the content parameter to a file and to specify the key to be used to access that data with the key parameter. The delete subroutine removes the key specified by the key parameter and the data to which that key points. The delete subroutine does not actually reclaim the file space, but it does make it available for reuse. The firstkey and nextkey subroutines make a linear pass through all of the keys in a data base. The firstkey subroutine returns the first key in the data base. The nextkey subroutine returns the next key in the data base. For example, the following code makes a linear pass through a data base: for (key = dbm_firstkey(db); key.dptr != NULL; key = dbm_nextkey(db)) { ... } The order of keys that are returned by firstkey and nextkey depend on the hashing function. RETURN VALUE All of the ndbm subroutines that return an int value return 0 upon successful completion, and they return a negative value if an error occurs. Subroutines that return a datum value indicate an error by setting the dptr field to NULL. RELATED INFORMATION In this book: "dbm." Processed October 11, 1991 NDBM(3x,L) 2