]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
macro: also move FOREACH_ARRAY()/FOREACH_ELEMENT() to fundamental
authorLennart Poettering <lennart@poettering.net>
Mon, 24 Jun 2024 13:54:47 +0000 (15:54 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 26 Jun 2024 14:01:06 +0000 (16:01 +0200)
This is also very useful in EFI code.

src/basic/macro.h
src/fundamental/macro-fundamental.h

index 72910d9c383dd95f11a5d21064df41b0e056c75d..8343528e85b5eb087f640155384b83ddec6e2c7a 100644 (file)
@@ -263,18 +263,6 @@ static inline int __coverity_check_and_return__(int condition) {
 /* Pointers range from NULL to POINTER_MAX */
 #define POINTER_MAX ((void*) UINTPTR_MAX)
 
-#define _FOREACH_ARRAY(i, array, num, m, end)                           \
-        for (typeof(array[0]) *i = (array), *end = ({                   \
-                                typeof(num) m = (num);                  \
-                                (i && m > 0) ? i + m : NULL;            \
-                        }); end && i < end; i++)
-
-#define FOREACH_ARRAY(i, array, num)                                    \
-        _FOREACH_ARRAY(i, array, num, UNIQ_T(m, UNIQ), UNIQ_T(end, UNIQ))
-
-#define FOREACH_ELEMENT(i, array)                                 \
-        FOREACH_ARRAY(i, array, ELEMENTSOF(array))
-
 #define _DEFINE_TRIVIAL_REF_FUNC(type, name, scope)             \
         scope type *name##_ref(type *p) {                       \
                 if (!p)                                         \
index 2595f5501cc01422bd870e28fb7a11ee273ca790..38230c5f19d81e69bc2ef3601c90a4e31257f5ff 100644 (file)
@@ -549,3 +549,15 @@ static inline uint64_t ALIGN_OFFSET_U64(uint64_t l, uint64_t ali) {
 
 #define sizeof_field(struct_type, member) sizeof(((struct_type *) 0)->member)
 #define endoffsetof_field(struct_type, member) (offsetof(struct_type, member) + sizeof_field(struct_type, member))
+
+#define _FOREACH_ARRAY(i, array, num, m, end)                           \
+        for (typeof(array[0]) *i = (array), *end = ({                   \
+                                typeof(num) m = (num);                  \
+                                (i && m > 0) ? i + m : NULL;            \
+                        }); end && i < end; i++)
+
+#define FOREACH_ARRAY(i, array, num)                                    \
+        _FOREACH_ARRAY(i, array, num, UNIQ_T(m, UNIQ), UNIQ_T(end, UNIQ))
+
+#define FOREACH_ELEMENT(i, array)                                 \
+        FOREACH_ARRAY(i, array, ELEMENTSOF(array))