dbopen(3) Library Functions Manual dbopen(3) dbopen - LIBRARY Standard C library (libc, -lc) #include #include #include #include DB *dbopen(const char *file, int flags, int mode, DBTYPE type, const void *openinfo); Note well: This page documents interfaces provided up until glibc 2.1. Since glibc 2.2, glibc no longer provides these interfaces. Probably, you are looking for the APIs provided by the libdb library instead. dbopen() is the library interface to database files. The supported file formats are btree, hashed, and UNIX file oriented. The btree format is a representation of a sorted, balanced tree structure. The hashed format is an extensible, dynamic hashing scheme. The flat-file format is a byte stream file with fixed or variable length records. The formats and file-format-specific information are described in detail in their respective manual pages btree(3), hash(3), and recno(3). dbopen() file / . , , file NULL. flags mode , open(2), O_CREAT, O_EXCL, O_EXLOCK, O_NONBLOCK, O_RDONLY, O_RDWR, O_SHLOCK O_TRUNC. O_WRONLY . type DBTYPE ( ) DB_BTREE, DB_HASH DB_RECNO. openinfo , , . openinfo NULL, . dbopen() DB NULL . DB , , : typedef struct { DBTYPE type; int (*close)(const DB *db); int (*del)(const DB *db, const DBT *key, unsigned int flags); int (*fd)(const DB *db); int (*get)(const DB *db, DBT *key, DBT *data, unsigned int flags); int (*put)(const DB *db, DBT *key, const DBT *data, unsigned int flags); int (*sync)(const DB *db, unsigned int flags); int (*seq)(const DB *db, DBT *key, DBT *data, unsigned int flags); } DB; , . , dbopen(), / . type ( ). close , , (-). / , close sync . close -1 ( , , errno) 0 . del / . flag : R_CURSOR , . . delete -1 ( errno), 0 1, key . fd , , . , , , dbopen() file. fcntl(2) flock(2). - , . . fd -1 ( , , errno) . get , . , key, , data. get -1 ( , , errno), 0 1, key . put , / . flag : R_CURSOR /, . . R_IAFTER , key; /. / key ( DB_RECNO). R_IBEFORE , key; /. / key ( DB_RECNO). R_NOOVERWRITE /, . R_SETCURSOR /, ( DB_BTREE DB_RECNO). R_SETCURSOR DB_BTREE DB_RECNO, , , . R_IAFTER R_IBEFORE DB_RECNO, , . , , , . put /, . put -1 ( , , errno), 0 1, flag R_NOOVERWRITE . seq , . , key, -- , data. / , <<>> del, get, put sync. , . . , , , , . : R_CURSOR , . get , . , DB_BTREE , . -- . . R_FIRST / , . R_LAST / , . DB_BTREE DB_RECNO. R_NEXT /, . , , R_FIRST. R_PREV /, . , , R_LAST. DB_BTREE DB_RECNO. R_LAST R_PREV DB_BTREE DB_RECNO, , . seq -1 ( errno), 0 1, /, , . DB_RECNO, ( /), seq 2. sync , . , sync . flag : R_RECNOSYNC DB_RECNO sync btree, recno, recno (. bfname recno(3)). sync -1 ( errno) 0 . / /. : typedef struct { void *data; size_t size; } DBT; DBT : data . size . , . , . dbopen() errno , open(2) malloc(3), : EFTYPE . EINVAL ( , . .) , (, ), . close errno close(2), read(2), write(2), free(3) fsync(2). The del, get, put, and seq routines may fail and set errno for any of the errors specified for the library routines read(2), write(2), free(3), or malloc(3). fd errno ENOENT ( , ). sync errno fsync(2). DBT <> , , . . - , . . btree(3), hash(3), mpool(3), recno(3) LIBTP: Portable, Modular Transactions for UNIX, Margo Seltzer, Michael Olson, USENIX proceedings, Winter 1992. Yuri Kozlov ; GNU 3 , . . , , . 4.4 Berkeley Distribution 31 2023 . dbopen(3)