]> mj.ucw.cz Git - libucw.git/blob - lib/db.h
Rewritten ff-binary.
[libucw.git] / lib / db.h
1 /*
2  *      UCW Library -- Fast Database Management Routines
3  *
4  *      (c) 1999--2001 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #ifndef _UCW_DB_H
11 #define _UCW_DB_H
12
13 struct sdbm;
14
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 */
22 };
23
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);
34
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
40                                          * may be impossible.
41                                          */
42 #define SDBM_FSYNC              16      /* When syncing, call fsync() */
43
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 */
49
50 #endif