]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
Add mdb_cursor_is_db()
authorHoward Chu <hyc@openldap.org>
Thu, 31 Aug 2017 14:44:31 +0000 (15:44 +0100)
committerHoward Chu <hyc@openldap.org>
Sat, 10 Oct 2020 12:06:09 +0000 (13:06 +0100)
Return 1 if the cursor is pointing to a named DB record

libraries/liblmdb/lmdb.h
libraries/liblmdb/mdb.c
libraries/liblmdb/mdb_dump.c
libraries/liblmdb/mdb_stat.c

index f9f847f1ce300119697996c74bb8702f79da9082..d6a422d7cb8caa6ef96ac36c733944ccb5c657a6 100644 (file)
@@ -1506,6 +1506,13 @@ MDB_txn *mdb_cursor_txn(MDB_cursor *cursor);
         */
 MDB_dbi mdb_cursor_dbi(MDB_cursor *cursor);
 
+       /** @brief Check if the cursor is pointing to a named database record.
+        *
+        * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
+        * @return 1 if current record is a named database, 0 otherwise.
+        */
+int mdb_cursor_is_db(MDB_cursor *cursor);
+
        /** @brief Retrieve by cursor.
         *
         * This function retrieves key/data pairs from the database. The address and length
index 8f2a18ccd620e45a5f5b4f7d6199b28a01b2c70f..1eebb153f226c18d73902fe21abb107774e24541 100644 (file)
@@ -9087,6 +9087,18 @@ mdb_cursor_dbi(MDB_cursor *mc)
        return mc->mc_dbi;
 }
 
+int
+mdb_cursor_is_db(MDB_cursor *mc)
+{
+
+       if (mc && (mc->mc_flags & C_INITIALIZED) && mc->mc_snum) {
+               MDB_node *leaf = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]);
+               if ((leaf->mn_flags & (F_DUPDATA|F_SUBDATA)) == F_SUBDATA)
+                       return 1;
+       }
+       return 0;
+}
+
 /** Replace the key for a branch node with a new key.
  * Set #MDB_TXN_ERROR on failure.
  * @param[in] mc Cursor pointing to the node to operate on.
index 57e79837df70c91a3302a1f3ac004fa64e86810c..fa1ca2966bf5aea6ee41ff7db75a36d6d41718db 100644 (file)
@@ -272,7 +272,7 @@ int main(int argc, char *argv[])
                }
                while ((rc = mdb_cursor_get(cursor, &key, NULL, MDB_NEXT_NODUP)) == 0) {
                        MDB_dbi db2;
-                       if (memchr(key.mv_data, '\0', key.mv_size-1) || ((char *)key.mv_data)[key.mv_size=1] != '\0')
+                       if (!mdb_cursor_is_db(cursor))
                                continue;
                        count++;
                        rc = mdb_dbi_open(txn, key.mv_data, 0, &db2);
index a94f5cd9facab762084e244b946903dddc7de063..f274a4666c0edae7da77a5fb6f04b840258e2390 100644 (file)
@@ -229,7 +229,7 @@ int main(int argc, char *argv[])
                }
                while ((rc = mdb_cursor_get(cursor, &key, NULL, MDB_NEXT_NODUP)) == 0) {
                        MDB_dbi db2;
-                       if (memchr(key.mv_data, '\0', key.mv_size-1) || ((char *)key.mv_data)[key.mv_size-1] != '\0')
+                       if (!mdb_cursor_is_db(cursor))
                                continue;
                        rc = mdb_dbi_open(txn, key.mv_data, 0, &db2);
                        if (rc == MDB_SUCCESS)