From 28224928bd4706515afc2885d16ca45389fc81ee Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Fri, 3 Feb 2017 15:48:06 +0100 Subject: lib: Retrieve number of children of a RIB node --- src/lib/rib.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/lib/rib.c b/src/lib/rib.c index 31ab372f..e0456b6f 100644 --- a/src/lib/rib.c +++ b/src/lib/rib.c @@ -690,7 +690,8 @@ bool rib_has(const char * path) { struct rnode * node; - assert(path); + if (path == NULL) + return -EINVAL; pthread_rwlock_rdlock(&rib.lock); @@ -710,8 +711,8 @@ ssize_t rib_children(const char * path, ssize_t i = 0; - assert(path); - assert(children); + if (path == NULL) + return -EINVAL; pthread_rwlock_rdlock(&rib.lock); @@ -721,6 +722,12 @@ ssize_t rib_children(const char * path, return -EPERM; } + if (children == NULL) { + pthread_rwlock_unlock(&rib.lock); + assert((ssize_t) node->chlen >= 0); + return (ssize_t) node->chlen; + } + if (node->chlen == 0) { pthread_rwlock_unlock(&rib.lock); *children = NULL; -- cgit v1.2.3