There are multiple places in libbpf where iteration of struct/union members is required. Instead of open-coding it let's introduce a convenience macro. Signed-off-by: Nikolay Borisov <nborisov@xxxxxxxx> --- tools/lib/bpf/btf.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h index 061839f04525..74039f8afc63 100644 --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h @@ -578,6 +578,12 @@ static inline struct btf_decl_tag *btf_decl_tag(const struct btf_type *t) return (struct btf_decl_tag *)(t + 1); } +#define for_each_member(i, struct_type, member) \ + for (i = 0, member = btf_members(struct_type); \ + i < btf_vlen(struct_type); \ + i++, member++) + + #ifdef __cplusplus } /* extern "C" */ #endif -- 2.25.1