nmdb: Add LevelDB support
[nmdb.git] / nmdb / be-qdbm.c
blob4a1291e0f3e316bdb1a7a68f0faf732eac7cdbdb
2 #if BE_ENABLE_QDBM
4 #include <depot.h> /* QDBM's Depot API */
5 #include <stdlib.h>
7 #include "be.h"
10 int qdbm_set(struct db_conn *db, const unsigned char *key, size_t ksize,
11 unsigned char *val, size_t vsize);
12 int qdbm_get(struct db_conn *db, const unsigned char *key, size_t ksize,
13 unsigned char *val, size_t *vsize);
14 int qdbm_del(struct db_conn *db, const unsigned char *key, size_t ksize);
15 int qdbm_close(struct db_conn *db);
18 struct db_conn *qdbm_open(const char *name, int flags)
20 int f;
21 struct db_conn *db;
22 DEPOT *qdbm_db;
24 f = DP_OREADER | DP_OWRITER | DP_ONOLCK | DP_OCREAT;
25 qdbm_db = dpopen(name, f, 0);
26 if (qdbm_db == NULL)
27 return NULL;
29 db = malloc(sizeof(struct db_conn));
30 if (db == NULL) {
31 dpclose(qdbm_db);
32 return NULL;
35 db->conn = qdbm_db;
36 db->set = qdbm_set;
37 db->get = qdbm_get;
38 db->del = qdbm_del;
39 db->firstkey = NULL;
40 db->nextkey = NULL;
41 db->close = qdbm_close;
43 return db;
47 int qdbm_close(struct db_conn *db)
49 int rv;
51 rv = dpclose(db->conn);
52 free(db);
53 return rv;
57 int qdbm_set(struct db_conn *db, const unsigned char *key, size_t ksize,
58 unsigned char *val, size_t vsize)
60 return dpput(db->conn, (char *) key, ksize,
61 (char *) val, vsize, DP_DOVER);
65 int qdbm_get(struct db_conn *db, const unsigned char *key, size_t ksize,
66 unsigned char *val, size_t *vsize)
68 int rv;
70 rv = dpgetwb(db->conn, (char *) key, ksize, 0, *vsize, (char *) val);
71 if (rv >= 0) {
72 *vsize = rv;
73 return 1;
74 } else {
75 return 0;
79 int qdbm_del(struct db_conn *db, const unsigned char *key, size_t ksize)
81 return dpout(db->conn, (char *) key, ksize);
84 #else
86 #include <stddef.h> /* NULL */
88 struct db_conn *qdbm_open(const char *name, int flags)
90 return NULL;
93 #endif