From 6e19da5336b8681d16970bef0bfe30973f4e50ba Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Wed, 15 Feb 2023 08:24:44 -0600 Subject: server: add a basic container_of macro Add a basic container_of macro to list.h. This is primarily for systems in which container_of has no definition. Signed-off-by: Danny Holman --- server/include/list.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/include/list.h b/server/include/list.h index fc3af68..b75e846 100644 --- a/server/include/list.h +++ b/server/include/list.h @@ -3,6 +3,12 @@ #include +#ifndef container_of +#define container_of(ptr, type, member) ({ \ + const typeof(((type*)0)->member)*__mptr = (ptr); \ + (type*)((char*)__mptr - offsetof(type, member)); }) +#endif + struct list_head { struct list_head *next; struct list_head *prev; -- cgit v1.2.3