NeoMutt  2023-05-17-56-ga67199
Teaching an old dog new tricks
DOXYGEN
qdbm.c
Go to the documentation of this file.
1
33#include "config.h"
34#include <stddef.h>
35#include <depot.h>
36#include <stdbool.h>
37#include <villa.h>
38#include "mutt/lib.h"
39#include "lib.h"
40
44static void *store_qdbm_open(const char *path)
45{
46 if (!path)
47 return NULL;
48
49 return vlopen(path, VL_OWRITER | VL_OCREAT, VL_CMPLEX);
50}
51
55static void *store_qdbm_fetch(void *store, const char *key, size_t klen, size_t *vlen)
56{
57 if (!store)
58 return NULL;
59
60 VILLA *db = store;
61 int sp = 0;
62 void *rv = vlget(db, key, klen, &sp);
63 *vlen = sp;
64 return rv;
65}
66
70static void store_qdbm_free(void *store, void **ptr)
71{
72 FREE(ptr);
73}
74
78static int store_qdbm_store(void *store, const char *key, size_t klen, void *value, size_t vlen)
79{
80 if (!store)
81 return -1;
82
83 VILLA *db = store;
84 /* Not sure if dbecode is reset on success, so better to explicitly return 0
85 * on success */
86 bool success = vlput(db, key, klen, value, vlen, VL_DOVER);
87 return success ? 0 : dpecode ? dpecode : -1;
88}
89
93static int store_qdbm_delete_record(void *store, const char *key, size_t klen)
94{
95 if (!store)
96 return -1;
97
98 VILLA *db = store;
99 /* Not sure if dbecode is reset on success, so better to explicitly return 0
100 * on success */
101 bool success = vlout(db, key, klen);
102 return success ? 0 : dpecode ? dpecode : -1;
103}
104
108static void store_qdbm_close(void **ptr)
109{
110 if (!ptr || !*ptr)
111 return;
112
113 VILLA *db = *ptr;
114 vlclose(db);
115 *ptr = NULL;
116}
117
121static const char *store_qdbm_version(void)
122{
123 return "qdbm " _QDBM_VERSION;
124}
125
static void store_qdbm_close(void **ptr)
Implements StoreOps::close() -.
Definition: qdbm.c:108
static int store_qdbm_delete_record(void *store, const char *key, size_t klen)
Implements StoreOps::delete_record() -.
Definition: qdbm.c:93
static void * store_qdbm_fetch(void *store, const char *key, size_t klen, size_t *vlen)
Implements StoreOps::fetch() -.
Definition: qdbm.c:55
static void store_qdbm_free(void *store, void **ptr)
Implements StoreOps::free() -.
Definition: qdbm.c:70
static void * store_qdbm_open(const char *path)
Implements StoreOps::open() -.
Definition: qdbm.c:44
static int store_qdbm_store(void *store, const char *key, size_t klen, void *value, size_t vlen)
Implements StoreOps::store() -.
Definition: qdbm.c:78
static const char * store_qdbm_version(void)
Implements StoreOps::version() -.
Definition: qdbm.c:121
#define FREE(x)
Definition: memory.h:43
Convenience wrapper for the library headers.
Key value store.
#define STORE_BACKEND_OPS(_name)
Definition: lib.h:159