tree data CHANGE add lyd_free_withsiblings()
diff --git a/src/tree_data.h b/src/tree_data.h
index 66c6328..740750b 100644
--- a/src/tree_data.h
+++ b/src/tree_data.h
@@ -545,13 +545,20 @@
struct lyd_node *lyd_parse_path(struct ly_ctx *ctx, const char *path, LYD_FORMAT format, int options, const struct lyd_node **trees);
/**
- * @brief Free all the nodes in the data tree.
+ * @brief Free all the nodes (even parents of the node) in the data tree.
*
* @param[in] node Any of the nodes inside the tree.
*/
void lyd_free_all(struct lyd_node *node);
/**
+ * @brief Free all the sibling nodes.
+ *
+ * @param[in] node Any of the sibling nodes to free.
+ */
+void lyd_free_withsiblings(struct lyd_node *node);
+
+/**
* @brief Free (and unlink) the specified data (sub)tree.
*
* __PARTIAL CHANGE__ - validate after the final change on the data tree (see @ref howtodatamanipulators).
diff --git a/src/tree_data_free.c b/src/tree_data_free.c
index 9d2d7a0..b8c5329 100644
--- a/src/tree_data_free.c
+++ b/src/tree_data_free.c
@@ -198,8 +198,8 @@
lyd_free_subtree(node->schema->module->ctx, node, 1);
}
-API void
-lyd_free_all(struct lyd_node *node)
+static void
+lyd_free_(struct lyd_node *node, int top)
{
struct lyd_node *iter, *next;
@@ -207,8 +207,10 @@
return;
}
- /* get the first top-level sibling */
- for (; node->parent; node = (struct lyd_node*)node->parent);
+ /* get the first (top-level) sibling */
+ if (top) {
+ for (; node->parent; node = (struct lyd_node*)node->parent);
+ }
while (node->prev->next) {
node = node->prev;
}
@@ -218,3 +220,15 @@
lyd_free_subtree(iter->schema->module->ctx, iter, iter->parent ? 1 : 0);
}
}
+
+API void
+lyd_free_withsiblings(struct lyd_node *node)
+{
+ lyd_free_(node, 0);
+}
+
+API void
+lyd_free_all(struct lyd_node *node)
+{
+ lyd_free_(node, 1);
+}