]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
Added container_of(). This seems about the best place to put it, since
authorMichael Brown <mcb30@etherboot.org>
Thu, 23 Mar 2006 22:07:21 +0000 (22:07 +0000)
committerMichael Brown <mcb30@etherboot.org>
Thu, 23 Mar 2006 22:07:21 +0000 (22:07 +0000)
the definition of it uses offsetof(), and the two concepts are related.

src/include/stddef.h

index ee1f15410f3160b3a53bdb62752145518f1ab1a0..6f91d21915af8dbaf763b30f8aefa91f2c72ad1a 100644 (file)
@@ -2,12 +2,17 @@
 #define STDDEF_H
 
 /* for size_t */
-#include "stdint.h"
+#include <stdint.h>
 
 #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 */