]> Git Repo - J-u-boot.git/blobdiff - lib/alist.c
alist: Add for-loop helpers
[J-u-boot.git] / lib / alist.c
index b7928cad52003255cc725cb9f8fd57c41759db76..1a4b4fb9c40c263ec75f77611e74c7fe900aa856 100644 (file)
@@ -106,6 +106,34 @@ 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;
+}
+
+bool alist_chk_ptr(const struct alist *lst, const void *ptr)
+{
+       int index = alist_calc_index(lst, ptr);
+
+       return index >= 0 && index < lst->count;
+}
+
+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;
This page took 0.026873 seconds and 4 git commands to generate.