From: Howard Chu Date: Tue, 16 Aug 2011 23:47:15 +0000 (-0700) Subject: Add mdb_strerror(), mdb_env_set_flags() X-Git-Tag: OPENLDAP_REL_ENG_2_4_27~148^2~97 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=bab6be80775e1c49f876418c90d9d267694d387b;p=openldap Add mdb_strerror(), mdb_env_set_flags() --- diff --git a/libraries/libmdb/mdb.c b/libraries/libmdb/mdb.c index b71f1fd0f4..c13cb6c07f 100644 --- a/libraries/libmdb/mdb.c +++ b/libraries/libmdb/mdb.c @@ -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) { diff --git a/libraries/libmdb/mdb.h b/libraries/libmdb/mdb.h index 30d4e927ea..372dfc1364 100644 --- a/libraries/libmdb/mdb.h +++ b/libraries/libmdb/mdb.h @@ -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);