From: Hamish Coleman Date: Fri, 17 Feb 2017 07:51:35 +0000 (+0800) Subject: Add a helper to count the size of an iterator X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=7950f924afbd902b506bbaedfc5f7f1bce6eacc9;p=liboping.git Add a helper to count the size of an iterator --- 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