2 * Sherlock Library -- Fast Database Management Routines
4 * (c) 1999--2001 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
10 #ifndef _SHERLOCK_DB_H
11 #define _SHERLOCK_DB_H
15 struct sdbm_options { /* Set to 0 for default */
16 char *name; /* File name */
17 uns flags; /* See SDBM_xxx below */
18 uns page_order; /* Binary logarithm of file page size */
19 uns cache_size; /* Number of cached pages */
20 int key_size; /* Key size, -1=variable */
21 int val_size; /* Value size, -1=variable */
24 struct sdbm *sdbm_open(struct sdbm_options *);
25 void sdbm_close(struct sdbm *);
26 int sdbm_store(struct sdbm *, byte *key, uns keylen, byte *val, uns vallen);
27 int sdbm_replace(struct sdbm *, byte *key, uns keylen, byte *val, uns vallen); /* val == NULL -> delete */
28 int sdbm_delete(struct sdbm *, byte *key, uns keylen);
29 int sdbm_fetch(struct sdbm *, byte *key, uns keylen, byte *val, uns *vallen); /* val can be NULL */
30 void sdbm_rewind(struct sdbm *);
31 int sdbm_get_next(struct sdbm *, byte *key, uns *keylen, byte *val, uns *vallen); /* val can be NULL */
32 void sdbm_sync(struct sdbm *);
33 u32 sdbm_hash(byte *key, uns keylen);
35 #define SDBM_CREAT 1 /* Create the database if it doesn't exist */
36 #define SDBM_WRITE 2 /* Open the database in read/write mode */
37 #define SDBM_SYNC 4 /* Sync after each operation */
38 #define SDBM_FAST 8 /* Don't sync on directory splits -- results in slightly faster
39 * operation, but reconstruction of database after program crash
42 #define SDBM_FSYNC 16 /* When syncing, call fsync() */
44 #define SDBM_ERROR_BAD_KEY_SIZE -1 /* Fixed key size doesn't match */
45 #define SDBM_ERROR_BAD_VAL_SIZE -2 /* Fixed value size doesn't match */
46 #define SDBM_ERROR_TOO_LARGE -3 /* Key/value doesn't fit in buffer supplied */
47 #define SDBM_ERROR_READ_ONLY -4 /* Database has been opened read only */
48 #define SDBM_ERROR_GIANT -5 /* Key/value too large to fit in a page */