From da67ea3695201270357475c400616b8a96e96d00 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Thu, 11 Apr 2024 15:17:43 +0200 Subject: [PATCH] libsrx: factor out new function lydx_vdescend() Signed-off-by: Joachim Wiberg --- src/libsrx/src/lyx.c | 15 ++++++++++++--- src/libsrx/src/lyx.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/libsrx/src/lyx.c b/src/libsrx/src/lyx.c index cce39e3a..b669c2ad 100644 --- a/src/libsrx/src/lyx.c +++ b/src/libsrx/src/lyx.c @@ -101,13 +101,11 @@ struct lyd_node *lydx_get_child(struct lyd_node *parent, const char *name) return lydx_get_sibling(lyd_child(parent), name); } -struct lyd_node *lydx_get_descendant(struct lyd_node *from, ...) +struct lyd_node *lydx_vdescend(struct lyd_node *from, va_list ap) { struct lyd_node *node = NULL; const char *name; - va_list ap; - va_start(ap, from); while ((name = va_arg(ap, const char *))) { node = lydx_get_sibling(from, name); if (!node) @@ -115,6 +113,17 @@ struct lyd_node *lydx_get_descendant(struct lyd_node *from, ...) from = lyd_child(node); } + + return node; +} + +struct lyd_node *lydx_get_descendant(struct lyd_node *from, ...) +{ + struct lyd_node *node; + va_list ap; + + va_start(ap, from); + node = lydx_vdescend(from, ap); va_end(ap); return node; diff --git a/src/libsrx/src/lyx.h b/src/libsrx/src/lyx.h index 8b9e9e3f..e4ea6edc 100644 --- a/src/libsrx/src/lyx.h +++ b/src/libsrx/src/lyx.h @@ -35,6 +35,7 @@ bool lydx_get_diff(struct lyd_node *node, struct lydx_diff *nd); struct lyd_node *lydx_get_sibling(struct lyd_node *sibling, const char *name); struct lyd_node *lydx_get_child(struct lyd_node *parent, const char *name); +struct lyd_node *lydx_vdescend(struct lyd_node *from, va_list ap); struct lyd_node *lydx_get_descendant(struct lyd_node *from, ...); struct lyd_node *lydx_find_by_name(struct lyd_node *from, const char *by, const char *name);