From c4f0ced120a0d777cac4948f83408aa4d6262b28 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Sun, 19 Feb 2006 01:28:21 +0000 Subject: Added pj_list_size() git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@192 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/include/pj/list.h | 10 ++++++++++ pjlib/include/pj/list_i.h | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/pjlib/include/pj/list.h b/pjlib/include/pj/list.h index 4f2e5145..24328dec 100644 --- a/pjlib/include/pj/list.h +++ b/pjlib/include/pj/list.h @@ -249,6 +249,16 @@ PJ_IDECL(pj_list_type*) pj_list_search(pj_list_type *list, void *value, ); +/** + * Traverse the list to get the number of elements in the list. + * + * @param list The list head. + * + * @return Number of elements. + */ +PJ_IDECL(pj_size_t) pj_list_size(pj_list_type *list); + + /** * @} */ diff --git a/pjlib/include/pj/list_i.h b/pjlib/include/pj/list_i.h index c6d95c80..2a8bf582 100644 --- a/pjlib/include/pj/list_i.h +++ b/pjlib/include/pj/list_i.h @@ -116,3 +116,17 @@ pj_list_search(pj_list_type *list, void *value, return p==list ? NULL : p; } + +PJ_IDEF(pj_size_t) pj_list_size(pj_list_type *list) +{ + pj_list *node = (pj_list*) ((pj_list*)list)->next; + pj_size_t count = 0; + + while (node != list) { + ++count; + node = node->next; + } + + return count; +} + -- cgit v1.2.3