From 8499c4f84a664bedbdf5a5689cb02420909f1968 Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Sat, 19 Sep 2015 01:25:54 +0200 Subject: [PATCH] common: Add new function strlist_length. * common/strlist.c (strlist_length): New function. -- Signed-off-by: Neal H. Walfield . --- common/strlist.c | 10 ++++++++++ common/strlist.h | 1 + 2 files changed, 11 insertions(+) diff --git a/common/strlist.c b/common/strlist.c index 967509c56..9bd6195f9 100644 --- a/common/strlist.c +++ b/common/strlist.c @@ -221,3 +221,13 @@ strlist_find (strlist_t haystack, const char *needle) return haystack; return NULL; } + +int +strlist_length (strlist_t list) +{ + int i; + for (i = 0; list; list = list->next) + i ++; + + return i; +} diff --git a/common/strlist.h b/common/strlist.h index 5c17ce69f..fccce8704 100644 --- a/common/strlist.h +++ b/common/strlist.h @@ -56,6 +56,7 @@ strlist_t strlist_last (strlist_t node); char * strlist_pop (strlist_t *list); strlist_t strlist_find (strlist_t haystack, const char *needle); +int strlist_length (strlist_t list); #define FREE_STRLIST(a) do { free_strlist((a)); (a) = NULL ; } while(0)