Added pj_list_size()

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@192 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
Benny Prijono 2006-02-19 01:28:21 +00:00
parent f239cfa75c
commit a5f4ff2b39
2 changed files with 24 additions and 0 deletions

View File

@ -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);
/**
* @}
*/

View File

@ -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;
}