diff options
author | Danny Holman <dholman@gymli.org> | 2023-02-15 08:24:44 -0600 |
---|---|---|
committer | Danny Holman <dholman@gymli.org> | 2023-02-15 08:28:02 -0600 |
commit | 6e19da5336b8681d16970bef0bfe30973f4e50ba (patch) | |
tree | b276528bb2873ee26a0c86a69c00b580b72fc30b /server | |
parent | 36d00051de9152546eddfbc84223cee251aee87a (diff) |
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 <dholman@gymli.org>
Diffstat (limited to 'server')
-rw-r--r-- | server/include/list.h | 6 |
1 files changed, 6 insertions, 0 deletions
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 <stddef.h> +#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; |