diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2021-09-21 21:57:26 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2021-09-21 21:57:26 +0200 |
commit | 13293d178731bba7d77123e57bc08925d285d522 (patch) | |
tree | 8f016fa188cec8a0215c961c1cc832c2b4bdcd4a /src/list.c | |
parent | ca197d7fc187e205a0e733be1722e6e8e03515c2 (diff) | |
download | dns-13293d178731bba7d77123e57bc08925d285d522.tar.gz |
list: add length and tests
Diffstat (limited to 'src/list.c')
-rw-r--r-- | src/list.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -28,8 +28,19 @@ int list_sort ( list_element_t** _root ) { return -1; } -int list_length ( list_element_t* _root ) { - return -1; +int list_length ( list_element_t** _root ) { + list_element_t** iter = _root; + int ret = 0; + + if( !_root ) + return -1; + + while(*iter) { + ret ++; + iter = & (*iter)->next; + } + + return ret; } void* list_pop_front ( list_element_t** _root ) { |