From: aliguori Date: Thu, 21 Aug 2008 20:11:11 +0000 (+0000) Subject: add container_of() macro to osdep.h (Gerd Hoffmann) X-Git-Tag: 0.10.0-0maemo1~1286 X-Git-Url: http://git.maemo.org/git/?a=commitdiff_plain;h=62a6e3e19a35e19a66abe6eec66005defac06d7c;p=qemu add container_of() macro to osdep.h (Gerd Hoffmann) From linux kernel sources, xen bits will use it, put it into a place where others can see and use it too ;) Signed-off-by: Gerd Hoffmann Signed-off-by: Anthony Liguori git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5057 c046a42c-6fe2-441c-8c8c-71466251a162 --- diff --git a/osdep.h b/osdep.h index 6312e7a..09ebace 100644 --- a/osdep.h +++ b/osdep.h @@ -23,6 +23,10 @@ #define unlikely(x) __builtin_expect(!!(x), 0) #endif +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) + #ifndef MIN #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif