From 7950f924afbd902b506bbaedfc5f7f1bce6eacc9 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 17 Feb 2017 15:51:35 +0800 Subject: [PATCH] Add a helper to count the size of an iterator --- src/liboping.c | 14 ++++++++++++++ src/oping.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/liboping.c b/src/liboping.c index fc9ed65..7af4e4a 100644 --- a/src/liboping.c +++ b/src/liboping.c @@ -1722,6 +1722,20 @@ pingobj_iter_t *ping_iterator_next (pingobj_iter_t *iter) return ((pingobj_iter_t *) iter->next); } +int ping_iterator_count (pingobj_t *obj) +{ + if (obj == NULL) + return 0; + + int count = 0; + pingobj_iter_t *iter = obj->head; + while(iter) { + count++; + iter = iter->next; + } + return count; +} + int ping_iterator_get_info (pingobj_iter_t *iter, int info, void *buffer, size_t *buffer_len) { diff --git a/src/oping.h b/src/oping.h index 1970ef2..50d11fb 100644 --- a/src/oping.h +++ b/src/oping.h @@ -75,6 +75,7 @@ int ping_host_remove (pingobj_t *obj, const char *host); pingobj_iter_t *ping_iterator_get (pingobj_t *obj); pingobj_iter_t *ping_iterator_next (pingobj_iter_t *iter); +int ping_iterator_count (pingobj_t *obj); #define PING_INFO_HOSTNAME 1 #define PING_INFO_ADDRESS 2 -- 2.30.2