From 2e776bd36eae2369325f32c58b6beaaa5a0aff24 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 11 Aug 2011 04:00:19 -0700 Subject: [PATCH] More DB checks --- libraries/libmdb/mdb.c | 33 ++++++++++++++++++++++++++++++--- libraries/libmdb/mdb.h | 2 +- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/libraries/libmdb/mdb.c b/libraries/libmdb/mdb.c index 667d44c5f9..6d90db24b5 100644 --- a/libraries/libmdb/mdb.c +++ b/libraries/libmdb/mdb.c @@ -1659,7 +1659,7 @@ mdb_get(MDB_txn *txn, MDB_dbi dbi, assert(data); DPRINTF("===> get key [%.*s]", (int)key->mv_size, (char *)key->mv_data); - if (txn == NULL || dbi >= txn->mt_numdbs) + if (txn == NULL || !dbi || dbi >= txn->mt_numdbs) return EINVAL; if (key->mv_size == 0 || key->mv_size > MAXKEYSIZE) { @@ -2673,7 +2673,7 @@ mdb_del(MDB_txn *txn, MDB_dbi dbi, assert(key != NULL); - if (txn == NULL || dbi >= txn->mt_numdbs) + if (txn == NULL || !dbi || dbi >= txn->mt_numdbs) return EINVAL; if (F_ISSET(txn->mt_flags, MDB_TXN_RDONLY)) { @@ -3035,7 +3035,7 @@ mdb_put(MDB_txn *txn, MDB_dbi dbi, assert(key != NULL); assert(data != NULL); - if (txn == NULL || dbi >= txn->mt_numdbs) + if (txn == NULL || !dbi || dbi >= txn->mt_numdbs) return EINVAL; if (F_ISSET(txn->mt_flags, MDB_TXN_RDONLY)) { @@ -3171,3 +3171,30 @@ void mdb_close(MDB_txn *txn, MDB_dbi dbi) txn->mt_dbxs[dbi].md_name.mv_size = 0; free(ptr); } + +int mdb_set_compare(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp) +{ + if (txn == NULL || !dbi || dbi >= txn->mt_numdbs) + return EINVAL; + + txn->mt_dbxs[dbi].md_cmp = cmp; + return MDB_SUCCESS; +} + +int mdb_set_dupsort(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp) +{ + if (txn == NULL || !dbi || dbi >= txn->mt_numdbs) + return EINVAL; + + txn->mt_dbxs[dbi].md_dcmp = cmp; + return MDB_SUCCESS; +} + +int mdb_set_relfunc(MDB_txn *txn, MDB_dbi dbi, MDB_rel_func *rel) +{ + if (txn == NULL || !dbi || dbi >= txn->mt_numdbs) + return EINVAL; + + txn->mt_dbxs[dbi].md_rel = rel; + return MDB_SUCCESS; +} diff --git a/libraries/libmdb/mdb.h b/libraries/libmdb/mdb.h index 90275233fa..0ac2e35252 100644 --- a/libraries/libmdb/mdb.h +++ b/libraries/libmdb/mdb.h @@ -100,6 +100,7 @@ typedef struct MDB_stat { int mdbenv_create(MDB_env **env); int mdbenv_open(MDB_env *env, const char *path, unsigned int flags, mode_t mode); int mdbenv_stat(MDB_env *env, MDB_stat *stat); +int mdbenv_sync(MDB_env *env); void mdbenv_close(MDB_env *env); int mdbenv_get_flags(MDB_env *env, unsigned int *flags); int mdbenv_get_path(MDB_env *env, const char **path); @@ -107,7 +108,6 @@ int mdbenv_set_mapsize(MDB_env *env, size_t size); int mdbenv_set_maxreaders(MDB_env *env, int readers); int mdbenv_get_maxreaders(MDB_env *env, int *readers); int mdbenv_set_maxdbs(MDB_env *env, int dbs); -int mdbenv_sync(MDB_env *env); int mdb_txn_begin(MDB_env *env, int rdonly, MDB_txn **txn); int mdb_txn_commit(MDB_txn *txn); -- 2.39.5