// filename: ndbm.h // Author: Zunhe JIN, Liping Wang // Date: July, 1998 // Description: // This is a substitute of the UNIX ndbm database engine. // We would like to call TH ndbm, where TH stands for // our mother school---Tsinghua University. // The only difference is that our new database engine can // only handle predefined size data. If there are several kind // length of records, just fix it to the maximum and we can // deal the rest for you. The advantage over the UNIX ndbm // is that TH can save more disk space, sometimes more than // 10 times when the data length is bigger that 1k bytes. // We are now testing the performance and will publish it later. // All the interfaces we provide here are the same with // that of the ndbm database. So when you face a problem // or want to look up the detail of the interface description, // just key in the following command on UNIX consol: // $ man ndbm // You will get the whole manual. // char * SCCS_VER="@(#)ndbm.h 1.1 04/15/02"; #ifndef _NDBM_H #define _NDBM_H //#pragma ident "@(#)ndbm.h 1.7 92/07/14 SMI" /* SVr4.0 1.1 */ //#ifdef __cplusplus //extern "C" { //#endif #define PBLKSIZ 1024 #define DBLKSIZ 4096 typedef struct { int dbm_pagf; /* open page file */ int dbm_flags; /* flags, see below */ char dbm_pagbuf[PBLKSIZ]; /* page file block buffer */ //this buf contains the content, // its length should be longer than MAX_DATA_SIZE. //otherwise a read-disk operation will overwrite dbm_dirbuf. char dbm_dirbuf[DBLKSIZ]; /* directory file block buffer */ //this buf contains the key, // its length should be longer than MAX_KEY_SIZE. //otherwise a read-disk operation will overwrite following fields. char *dbm_table; /* dbm table of location mapping */ char *dbm_holelist; /* hole list in the page file */ int dbm_maxslot; /* the biggest slot number */ int dbm_curslot; /* current slot number */ char i_have_lock_on_file; /* 1: I have write_lock, can wirte. */ char dbm_filename[32]; //as key in hash array/ } DBM; #define _DBM_RDONLY 0x1 /* data base open read-only */ #define _DBM_IOERR 0x2 /* data base I/O error */ #define dbm_rdonly(db) ((db)->dbm_flags & _DBM_RDONLY) #define dbm_error(db) ((db)->dbm_flags & _DBM_IOERR) /* use this one at your own risk! */ #define dbm_clearerr(db) ((db)->dbm_flags &= ~_DBM_IOERR) /* for fstat(2) */ #define dbm_dirfno(db) ((db)->dbm_dirf) #define dbm_pagfno(db) ((db)->dbm_pagf) typedef struct { char *dptr; int dsize; } datum; /* * flags to dbm_store() */ #define DBM_INSERT 0 #define DBM_REPLACE 1 DBM *dbm_open(char *, int, int); void dbm_close(DBM *); datum dbm_fetch(DBM *, datum); datum dbm_firstkey(DBM *); datum dbm_nextkey(DBM *); int dbm_delete(DBM *, datum); int dbm_store(DBM *, datum, datum, int); int dbm_commit(); //#ifdef __cplusplus //} //#endif #endif /* _NDBM_H */