69 dbt->flags = DB_DBT_USERMEM;
94 struct stat st = { 0 };
96 uint32_t createflags = DB_CREATE;
100 const int pagesize = 512;
115 rc = db_env_create(&ctx->
env, 0);
119 rc = (*ctx->
env->open)(ctx->
env, NULL, DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE, 0600);
124 rc = db_create(&ctx->
db, ctx->
env, 0);
128 if ((stat(path, &st) != 0) && (errno == ENOENT))
130 createflags |= DB_EXCL;
131 ctx->
db->set_pagesize(ctx->
db, pagesize);
134 rc = (*ctx->
db->open)(ctx->
db, NULL, path, NULL, DB_BTREE, createflags, 0600);
141 ctx->
db->close(ctx->
db, 0);
143 ctx->
env->close(ctx->
env, 0);
168 dbt_init(&dkey, (
void *) key, klen);
170 data.flags = DB_DBT_MALLOC;
172 ctx->
db->get(ctx->
db, NULL, &dkey, &data, 0);
189 static int store_bdb_store(
void *store,
const char *key,
size_t klen,
void *value,
size_t vlen)
199 dbt_init(&dkey, (
void *) key, klen);
201 databuf.flags = DB_DBT_USERMEM;
202 databuf.data = value;
206 return ctx->
db->put(ctx->
db, NULL, &dkey, &databuf, 0);
221 dbt_init(&dkey, (
void *) key, klen);
222 return ctx->
db->del(ctx->
db, NULL, &dkey, 0);
235 db->db->close(
db->db, 0);
236 db->env->close(
db->env, 0);
249 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.
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
static const char * mutt_buffer_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.