data FEATURE add lyd_first_sibling() function
diff --git a/src/tree_data.c b/src/tree_data.c
index ef44019..4e0e18b 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -3389,3 +3389,22 @@
return pos;
}
+
+API struct lyd_node *
+lyd_first_sibling(const struct lyd_node *node)
+{
+ struct lyd_node *start;
+
+ if (!node) {
+ return NULL;
+ }
+
+ /* get the first sibling */
+ if (node->parent) {
+ start = node->parent->child;
+ } else {
+ for (start = (struct lyd_node *)node; start->prev->next; start = start->prev);
+ }
+
+ return start;
+}
diff --git a/src/tree_data.h b/src/tree_data.h
index 1a2fb46..a5accd5 100644
--- a/src/tree_data.h
+++ b/src/tree_data.h
@@ -786,6 +786,15 @@
uint32_t lyd_list_pos(const struct lyd_node *instance);
/**
+ * @brief Get the first sibling of the given node.
+ *
+ * @param[in] node Node which first sibling is going to be the result.
+ * @return The first sibling of the given node or the node itself if it is the first child of the parent.
+ */
+struct lyd_node *
+lyd_first_sibling(const struct lyd_node *node);
+
+/**
* @brief Learn the length of LYB data.
*
* @param[in] data LYB data to examine.