ndbm.3

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 3 代码 · 共 176 行

3
176
字号
.\"	@(#)n\fIdb\fPm.3	6.6 (Berkeley) 5/20/86.\".TH ndbm 3.SH Namedbm_open, dbm_close, dbm_fetch, dbm_store, dbm_delete, dbm_firstkey, dbm_nextkey, dbm_error, dbm_clearerr \- data base subroutines.SH Syntax.nf.PP.ft B#include <ndbm.h>.PP.ft Btypedef struct {    char *dptr;    int dsize;} datum;.PP.ft BDBM *dbm_open(\fIfile\fP, \fIflags\fP, \fImode\fP)    char *\fIfile\fP;    int \fIflags\fP, \fImode\fP;.PP.ft Bvoid dbm_close(\fIdb\fP)    DBM *\fIdb\fP;.PP.ft Bdatum dbm_fetch(\fIdb\fP, \fIkey\fP)    DBM *\fIdb\fP;    datum \fIkey\fP;.PP.ft Bint dbm_store(\fIdb\fP, \fIkey\fP, \fIcontent\fP, \fIflags\fP)    DBM *\fIdb\fP;    datum \fIkey\fP, \fIcontent\fP;    int \fIflags\fP;.PP.ft Bint dbm_delete(\fIdb\fP, \fIkey\fP)    DBM *\fIdb\fP;    datum \fIkey\fP;.PP.ft Bdatum dbm_first\fIkey\fP(\fIdb\fP)    DBM *\fIdb\fP;.PP.ft Bdatum dbm_next\fIkey\fP(\fIdb\fP)    DBM *\fIdb\fP;.PP.ft Bint dbm_error(\fIdb\fP)    DBM *\fIdb\fP;.PP.ft Bint dbm_clearerr(\fIdb\fP)    DBM *\fIdb\fP;.SH DescriptionThese 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.MS dbm 3xlibrary, which managed only a single database..PPThe .IR key sand.IR content sare described by the.B datumtypedef.  A.B datumspecifies a string of.B dsizebytes pointed to by.B dptr.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 suffix.The second file contains all data and has .pag as its suffix..PPBefore a database can be accessed, it must be opened by.BR dbm_open .This will open and/or create the files.IR file .dirand.IR file .pagdepending on the flags parameter (see.MS open 2 )..PPOnce open, the data stored under a key is accessed by.B dbm_fetchand data is placed under a key by.BR dbm_store .The.I flagsfield can be eitherDBM_INSERTorDBM_REPLACE.DBM_INSERTwill only insert new entries into the database and will notchange an existing entry with the same key.DBM_REPLACEwill replace an existing entry if it has the same key.A key (and its associated contents) is deleted by.BR dbm_delete .A linear pass through all keys in a database may be made,in an (apparently) random order, by use of.B dbm_firstkeyand.BR dbm_nextkey ..B dbm_firstkeywill return the first key in the database..B dbm_nextkeywill return the next key in the database.This code will traverse the data base:.IP.B for(\fIkey\fP = \fBdbm_firstkey\fP(\fIdb\fP); \fIkey\fP.\fBdptr\fP != NULL; \fIkey\fP = \fBdbm_nextkey\fP(\fIdb\fP)).PP.B dbm_errorreturns non-zero when an error has occurred reading or writing the database..B dbm_clearerrresets the error condition on the named database..SH DiagnosticsAll functions that return an.B intindicate errors with negative values.  A zero return indicates ok.Routines that return a.B datumindicate errors with a null (0).B dptr.If.B dbm_storecalled with a.I flagsvalue ofDBM_INSERTfinds an existing entry with the same keyit returns 1..SH RestrictionsThe `.pag' file will contain holes so that its apparent size is aboutfour times its actual content.  Older systems may create realfile blocks for these holes when touched.  These files cannot be copiedby normal means (.PN cp, .PN cat, .PN tp, .PN tar, .PN ar )without filling in the holes..PP.B dptrpointers returned by these subroutines point into static storagethat is changed by subsequent calls..PPThe sum of the sizes of a key/content pair must not exceedthe internal block size (currently 4096 bytes).Moreover all key/content pairs that hash together must fit on a single block..B dbm_storewill return an error in the event that a disk block fills with inseparable data..PP.B dbm_deletedoes not physically reclaim file space,although it does make it available for reuse..PPThe order of keys presented by.B dbm_firstkeyand.B dbm_nextkeydepends on a hashing function, not on anything interesting..SH See Also.MS dbm 3X

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?