mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2026-06-13 15:03:58 +03:00
alist: Add a way to get the next element
Add a new function which returns the next element after the one provided, if it exists in the list. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
21
lib/alist.c
21
lib/alist.c
@@ -106,6 +106,27 @@ const void *alist_get_ptr(const struct alist *lst, uint index)
|
||||
return lst->data + index * lst->obj_size;
|
||||
}
|
||||
|
||||
int alist_calc_index(const struct alist *lst, const void *ptr)
|
||||
{
|
||||
uint index;
|
||||
|
||||
if (!lst->count || ptr < lst->data)
|
||||
return -1;
|
||||
|
||||
index = (ptr - lst->data) / lst->obj_size;
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
const void *alist_next_ptrd(const struct alist *lst, const void *ptr)
|
||||
{
|
||||
int index = alist_calc_index(lst, ptr);
|
||||
|
||||
assert(index != -1);
|
||||
|
||||
return alist_get_ptr(lst, index + 1);
|
||||
}
|
||||
|
||||
void *alist_ensure_ptr(struct alist *lst, uint index)
|
||||
{
|
||||
uint minsize = index + 1;
|
||||
|
||||
Reference in New Issue
Block a user