]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add fr_dlist_foreach
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 11 Jun 2021 15:49:10 +0000 (10:49 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 11 Jun 2021 15:49:10 +0000 (10:49 -0500)
src/lib/util/dlist.h

index 6dac2c1145090a4f27c9490e465ef2d3c0e848bb..6716778ee2f640b788ca139bdc1ea056fa5fc4cd 100644 (file)
@@ -56,6 +56,17 @@ typedef struct {
        size_t          num_elements;
 } fr_dlist_head_t;
 
+
+/** Iterate over the contents of a list
+ *
+ * @param[in] _list_head       to iterate over.
+ * @param[in] _type            of item the list contains.
+ * @param[in] _iter            Name of iteration variable.
+ *                             Will be declared in the scope of the loop.
+ */
+#define fr_dlist_foreach(_list_head, _type, _iter) \
+       for (_type *_iter = fr_dlist_head(_list_head); _iter; _iter = fr_dlist_next(_list_head, _iter))
+
 /** Find the dlist pointers within a list item
  *
  */
@@ -918,7 +929,7 @@ static inline void fr_dlist_recursive_sort(fr_dlist_head_t *head, void **ptr, fr
  * @param[in,out] list to sort
  * @param[in] cmp      comparison function to sort with
  */
-static inline void fr_dlist_sort (fr_dlist_head_t *list, fr_cmp_t cmp)
+static inline void fr_dlist_sort(fr_dlist_head_t *list, fr_cmp_t cmp)
 {
        void *head;
        fr_dlist_t *entry;
@@ -957,10 +968,8 @@ static inline void fr_dlist_sort (fr_dlist_head_t *list, fr_cmp_t cmp)
                }
                head = fr_dlist_next(list, head);
        }
-
 }
 
-
 #ifdef __cplusplus
 }
 #endif