Add mdb_strerror(), mdb_env_set_flags()

vmware
Howard Chu 13 years ago
parent 9902a7764e
commit bab6be8077
  1. 34
      libraries/libmdb/mdb.c
  2. 2
      libraries/libmdb/mdb.h

@ -460,6 +460,27 @@ mdb_version(int *maj, int *min, int *pat)
return MDB_VERSION_STRING;
}
static const char *errstr[] = {
"MDB_KEYEXIST: Key/data pair already exists",
"MDB_NOTFOUND: No matching key/data pair found",
"MDB_PAGE_NOTFOUND: Requested page not found",
"MDB_CORRUPTED: Located page was wrong type",
"MDB_PANIC: Update of meta page failed",
"MDB_VERSION_MISMATCH: Database environment version mismatch"
};
char *
mdb_strerror(int err)
{
if (!err)
return ("Successful return: 0");
if (err >= MDB_KEYEXIST && err <= MDB_VERSION_MISMATCH)
return (char *)errstr[err - MDB_KEYEXIST];
return strerror(err);
}
int
mdb_cmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b)
{
@ -3160,6 +3181,19 @@ mdb_put(MDB_txn *txn, MDB_dbi dbi,
return mdb_put0(txn, dbi, key, data, flags);
}
int
mdb_env_set_flags(MDB_env *env, unsigned int flag, int onoff)
{
#define CHANGEABLE (MDB_NOSYNC)
if ((flag & CHANGEABLE) != flag)
return EINVAL;
if (onoff)
env->me_flags |= flag;
else
env->me_flags &= ~flag;
return MDB_SUCCESS;
}
int
mdb_env_get_flags(MDB_env *env, unsigned int *arg)
{

@ -114,11 +114,13 @@ typedef struct MDB_stat {
} MDB_stat;
char *mdb_version(int *major, int *minor, int *patch);
char *mdb_strerror(int err);
int mdb_env_create(MDB_env **env);
int mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mode_t mode);
int mdb_env_stat(MDB_env *env, MDB_stat *stat);
int mdb_env_sync(MDB_env *env, int force);
void mdb_env_close(MDB_env *env);
int mdb_env_set_flags(MDB_env *env, unsigned int flags, int onoff);
int mdb_env_get_flags(MDB_env *env, unsigned int *flags);
int mdb_env_get_path(MDB_env *env, const char **path);
int mdb_env_set_mapsize(MDB_env *env, size_t size);

Loading…
Cancel
Save