[Date Prev][Date Next] [Chronological] [Thread] [Top]

(ITS#8275) [PATCH 1/2] Add mdb_dbi_name() function to get database name from a handle



Full_Name: Pavel Medvedev
Version: 
OS: 
URL: ftp://ftp.openldap.org/incoming/
Submission from: (NULL) (217.25.225.40)


---
 libraries/liblmdb/lmdb.h | 15 +++++++++++++++
 libraries/liblmdb/mdb.c  |  9 +++++++++
 2 files changed, 24 insertions(+)

diff --git a/libraries/liblmdb/lmdb.h b/libraries/liblmdb/lmdb.h
index e080e76..933a862 100644
- - a/libraries/liblmdb/lmdb.h
+++ b/libraries/liblmdb/lmdb.h
@@ -1136,6 +1136,21 @@ int  mdb_stat(MDB_txn *txn, MDB_dbi dbi, MDB_stat
*stat);
 	 */
 int mdb_dbi_flags(MDB_txn *txn, MDB_dbi dbi, unsigned int *flags);
 
+	/** @brief Return the DB name that was used in #mdb_dbi_open().
+	*
+	* @param[in] txn A transaction handle returned by #mdb_txn_begin()
+	* @param[in] dbi A database handle returned by #mdb_dbi_open()
+	* @param[out] path Address of a string pointer to contain the path. This
+	* is the actual string in the database, not a copy. It should not be
+	* altered in any way.
+	* @return A non-zero error value on failure and 0 on success. Some possible
+	* errors are:
+	* <ul>
+	*	<li>EINVAL - an invalid parameter was specified.
+	* </ul>
+	*/
+int mdb_dbi_name(MDB_txn *txn, MDB_dbi dbi, const char **name);
+
 	/** @brief Close a database handle. Normally unnecessary. Use with care:
 	 *
 	 * This call is not mutex protected. Handles should only be closed by
diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c
index 8f7f3b3..a2763f8 100644
--- a/libraries/liblmdb/mdb.c
+++ b/libraries/liblmdb/mdb.c
@@ -9541,6 +9541,15 @@ int mdb_dbi_flags(MDB_txn *txn, MDB_dbi dbi, unsigned int
*flags)
 	return MDB_SUCCESS;
 }
 
+int mdb_dbi_name(MDB_txn *txn, MDB_dbi dbi, const char **name)
+{
+	if (!TXN_DBI_EXIST(txn, dbi, DB_USRVALID) || !name)
+		return EINVAL;
+	/* safe since md_name is 0-terminated with strdup in mdb_dbi_open */
+	*name = txn->mtbxbxs[dbi].md_name.mv_data;
+	return MDB_SUCCESS;
+}
+
 /** Add all the DB's pages to the free list.
  * @param[in] mc Cursor on the DB to free.
  * @param[in] subs non-Zero to check for sub-DBs in this DB.