Skip to contentSkip to conversation

[5057] add container_of() macro to osdep.h (Gerd Hoffmann)

Qemu-devel Anthony Liguori 1 participant 1 message Aug 21, 2008

lore
Share & tools
lore
#0 lore raw

Revision: 5057

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5057
Author:   aliguori
Date:     2008-08-21 20:11:11 +0000 (Thu, 21 Aug 2008)

Log Message:
-----------
add container_of() macro to osdep.h (Gerd Hoffmann)

Quoted 1 line

From linux kernel sources, xen bits will use it, put it

into a place where others can see and use it too ;)

Modified Paths:
--------------
trunk/osdep.h

Modified: trunk/osdep.h
===================================================================

osdep.h +4 -0
@@ -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