@@ -246,3 +246,21 @@ void __free_ptr_list(struct ptr_list **listp)
*listp = NULL;
}
+
+void *ptr_list_nth_entry(struct ptr_list *list, unsigned int idx)
+{
+ struct ptr_list *head = list;
+
+ if (!head)
+ return NULL;
+
+ do {
+ unsigned int nr = list->nr;
+
+ if (idx < nr)
+ return list->list[idx];
+ else
+ idx -= nr;
+ } while ((list = list->next) != head);
+ return NULL;
+}
@@ -44,6 +44,7 @@ extern void concat_ptr_list(struct ptr_list *a, struct ptr_list **b);
extern void __free_ptr_list(struct ptr_list **);
extern int ptr_list_size(struct ptr_list *);
extern int linearize_ptr_list(struct ptr_list *, void **, int);
+extern void *ptr_list_nth_entry(struct ptr_list *, unsigned int idx);
/*
* Hey, who said that you can't do overloading in C?
Usually ptr lists are accessed iteratively via the FOR/END macros but in few case we may need to access a given element in a list, like for example when accessing a given argument of a function. Create an helper doing that instead of open coding it. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- ptrlist.c | 18 ++++++++++++++++++ ptrlist.h | 1 + 2 files changed, 19 insertions(+)