aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Iezzi <aiezzi@alessandroiezzi.it>2023-03-13 17:12:26 +0100
committerAlessandro Iezzi <aiezzi@alessandroiezzi.it>2023-03-13 17:12:26 +0100
commit3f846f386c6e51f707ab418b549e4fb4180960de (patch)
tree263d1dfe2ccd904257cb7e3dde9caa95c3de8f43
parent22ad5660800e534e18e653ed31ccaec650df8769 (diff)
downloadutils-3f846f386c6e51f707ab418b549e4fb4180960de.tar.gz
utils-3f846f386c6e51f707ab418b549e4fb4180960de.zip
Change data return in clist_iterator_next
We want only data and not the node structure.
-rw-r--r--src/list.c14
-rw-r--r--src/list.h2
2 files changed, 10 insertions, 6 deletions
diff --git a/src/list.c b/src/list.c
index 7714f5d..ea038f4 100644
--- a/src/list.c
+++ b/src/list.c
@@ -103,13 +103,17 @@ clist_iterator_has_next(iterator_t i)
return i.current != NULL;
}
-list_item_t
-clist_iterator_next(iterator_t *iterator)
+void *
+clist_iterator_next(iterator_t *i)
{
- struct list_item_t *current = iterator->current;
- iterator->current = iterator->current->next;
+ if (i == NULL || i->current == NULL)
+ return NULL;
- return current;
+ void *data = i->current->data;
+ /* `next` can be NULL */
+ i->current = i->current->next;
+
+ return data;
}
char *
diff --git a/src/list.h b/src/list.h
index c98f8e8..da0793d 100644
--- a/src/list.h
+++ b/src/list.h
@@ -41,7 +41,7 @@ void clist_add_all (list_t *, list_t *);
void clist_remove (list_t *, list_item_t *);
iterator_t clist_iterator (list_t *);
int clist_iterator_has_next(iterator_t);
-list_item_t *clist_iterator_next (iterator_t *);
+void *clist_iterator_next (iterator_t *);
char* clist_version (void);
#endif