summaryrefslogtreecommitdiffstats
path: root/src/include/stddef.h
diff options
context:
space:
mode:
authorMichael Brown2006-03-23 23:07:21 +0100
committerMichael Brown2006-03-23 23:07:21 +0100
commit508dcdb3035a2ef826e0feda39c7648df25c88ad (patch)
treebda6ea8d0acafacff3519382568cb2a2f65c4de1 /src/include/stddef.h
parentPick up the gPXE include files when building prototester. (diff)
downloadipxe-508dcdb3035a2ef826e0feda39c7648df25c88ad.tar.gz
ipxe-508dcdb3035a2ef826e0feda39c7648df25c88ad.tar.xz
ipxe-508dcdb3035a2ef826e0feda39c7648df25c88ad.zip
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.
Diffstat (limited to 'src/include/stddef.h')
-rw-r--r--src/include/stddef.h9
1 files 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 <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 */