From 508dcdb3035a2ef826e0feda39c7648df25c88ad Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 23 Mar 2006 22:07:21 +0000 Subject: [PATCH] Added container_of(). This seems about the best place to put it, since the definition of it uses offsetof(), and the two concepts are related. --- src/include/stddef.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/include/stddef.h b/src/include/stddef.h index ee1f1541..6f91d219 100644 --- a/src/include/stddef.h +++ b/src/include/stddef.h @@ -2,12 +2,17 @@ #define STDDEF_H /* for size_t */ -#include "stdint.h" +#include #undef NULL -#define NULL ((void *)0) +#define NULL ((void *)0) #undef offsetof #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) +#undef container_of +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) + #endif /* STDDEF_H */