2020-02-09 23:58:17 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <lmdb.h>
|
|
|
|
|
2020-04-18 14:34:43 +00:00
|
|
|
#include <config.h>
|
2020-04-16 23:38:25 +00:00
|
|
|
#include <constants.h>
|
2020-02-09 23:58:17 +00:00
|
|
|
|
|
|
|
void
|
2020-04-18 14:34:43 +00:00
|
|
|
database_setup(MDB_env **mdb_env, config_t *config)
|
2020-02-09 23:58:17 +00:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if(mdb_env_create(mdb_env) != 0)
|
|
|
|
{
|
|
|
|
perror("Can't create mdb handle");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if((err = mdb_env_set_maxdbs(*mdb_env, MDB_MAXDBS)) != 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "mdb_env_set_maxdbs error %s\n", mdb_strerror(err));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2020-04-18 14:34:43 +00:00
|
|
|
if(mdb_env_open(*mdb_env, config->database, MDB_NOSUBDIR, 0700) != 0)
|
2020-02-09 23:58:17 +00:00
|
|
|
{
|
|
|
|
perror("Can't open mdb file");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|