summaryrefslogtreecommitdiff
path: root/src/shared/macro.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/macro.h')
-rw-r--r--src/shared/macro.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/shared/macro.h b/src/shared/macro.h
index 1355aac908..1c0aa915ad 100644
--- a/src/shared/macro.h
+++ b/src/shared/macro.h
@@ -57,6 +57,17 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
#define ELEMENTSOF(x) (sizeof(x)/sizeof((x)[0]))
+/*
+ * container_of - cast a member of a structure out to the containing structure
+ * @ptr: the pointer to the member.
+ * @type: the type of the container struct this is embedded in.
+ * @member: the name of the member within the struct.
+ *
+ */
+#define container_of(ptr, type, member) ({ \
+ const typeof( ((type *)0)->member ) *__mptr = (ptr); \
+ (type *)( (char *)__mptr - offsetof(type,member) );})
+
#ifndef MAX
#define MAX(a,b) \
__extension__ ({ \