68 dbt->flags = DB_DBT_USERMEM;
93 struct stat st = { 0 };
95 uint32_t createflags = DB_CREATE;
99 const int pagesize = 512;
114 rc = db_env_create(&ctx->
env, 0);
118 rc = (*ctx->
env->open)(ctx->
env, NULL, DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE, 0600);
123 rc = db_create(&ctx->
db, ctx->
env, 0);
127 if ((stat(path, &st) != 0) && (errno == ENOENT))
129 createflags |= DB_EXCL;
130 ctx->
db->set_pagesize(ctx->
db, pagesize);
133 rc = (*ctx->
db->open)(ctx->
db, NULL, path, NULL, DB_BTREE, createflags, 0600);
140 ctx->
db->close(ctx->
db, 0);
142 ctx->
env->close(ctx->
env, 0);
167 dbt_init(&dkey, (
void *) key, klen);
169 data.flags = DB_DBT_MALLOC;
171 ctx->
db->get(ctx->
db, NULL, &dkey, &data, 0);
188static int store_bdb_store(
void *store,
const char *key,
size_t klen,
void *value,
size_t vlen)
198 dbt_init(&dkey, (
void *) key, klen);
200 databuf.flags = DB_DBT_USERMEM;
201 databuf.data = value;
205 return ctx->
db->put(ctx->
db, NULL, &dkey, &databuf, 0);
220 dbt_init(&dkey, (
void *) key, klen);
221 return ctx->
db->del(ctx->
db, NULL, &dkey, 0);
234 db->db->close(
db->db, 0);
235 db->env->close(
db->env, 0);
248 return DB_VERSION_STRING;
static void dbt_empty_init(DBT *dbt)
Initialise an empty BDB context.
static void dbt_init(DBT *dbt, void *data, size_t len)
Initialise a BDB context.
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
void buf_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
struct Buffer buf_make(size_t size)
Make a new buffer on the stack.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
int mutt_file_lock(int fd, bool excl, bool timeout)
(Try to) Lock a file using fcntl()
int mutt_file_unlock(int fd)
Unlock a file previously locked by mutt_file_lock()
static void store_bdb_close(void **ptr)
Implements StoreOps::close() -.
static int store_bdb_delete_record(void *store, const char *key, size_t klen)
Implements StoreOps::delete_record() -.
static void * store_bdb_fetch(void *store, const char *key, size_t klen, size_t *vlen)
Implements StoreOps::fetch() -.
static void store_bdb_free(void *store, void **ptr)
Implements StoreOps::free() -.
static void * store_bdb_open(const char *path)
Implements StoreOps::open() -.
static int store_bdb_store(void *store, const char *key, size_t klen, void *value, size_t vlen)
Implements StoreOps::store() -.
static const char * store_bdb_version(void)
Implements StoreOps::version() -.
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Convenience wrapper for the library headers.
#define STORE_BACKEND_OPS(_name)
String manipulation buffer.
char * data
Pointer to data.