diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2007-08-02 10:10:11 +0000 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2007-08-02 10:10:11 +0000 |
commit | 9ad676bab098d754b57265fc335a7f045e192d96 (patch) | |
tree | 3667c5b1442f1d9fda3498b500d6d21e46e201d8 /linkedlist.c | |
parent | dcec3c8c4e7bfb9c0cb904047d57188f6b377575 (diff) | |
download | rsyslog-9ad676bab098d754b57265fc335a7f045e192d96.tar.gz rsyslog-9ad676bab098d754b57265fc335a7f045e192d96.tar.xz rsyslog-9ad676bab098d754b57265fc335a7f045e192d96.zip |
enhanced linkedList class, new method to get count, new method to execute a
user-supplied function on all members
Diffstat (limited to 'linkedlist.c')
-rw-r--r-- | linkedlist.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/linkedlist.c b/linkedlist.c index 2e0d5052..4037193b 100644 --- a/linkedlist.c +++ b/linkedlist.c @@ -206,6 +206,50 @@ rsRetVal llFind(linkedList_t *pThis, void *pKey, void **ppData) return iRet; } + +/* provide the count of linked list elements + */ +rsRetVal llGetNumElts(linkedList_t *pThis, int *piCnt) +{ + DEFiRet; + + assert(pThis != NULL); + assert(piCnt != NULL); + + *piCnt = pThis->iNumElts; + + return iRet; +} + + +/* execute a function on all list members. The functions receives a + * user-supplied parameter, which may be either a simple value + * or a pointer to a structure with more data. If the user-supplied + * function does not return RS_RET_OK, this function here terminates. + * rgerhards, 2007-08-02 + */ +rsRetVal llExecFunc(linkedList_t *pThis, rsRetVal (*pFunc)(void*, void*), void* pParam) +{ + DEFiRet; + rsRetVal iRetLL; + void *pData; + linkedListCookie_t llCookie = NULL; + + assert(pThis != NULL); + assert(pFunc != NULL); + + while((iRetLL = llGetNextElt(pThis, &llCookie, (void**)&pData)) == RS_RET_OK) { + CHKiRet(pFunc(pData, pParam)); + } + + if(iRetLL != RS_RET_END_OF_LINKEDLIST) + iRet = iRetLL; + +finalize_it: + return iRet; +} + + /* * vi:set ai: */ |