chiark / gitweb /
build-sys: fix built with --disable-logind
[elogind.git] / src / shared / macro.h
index 1355aac90879ca287b4f08423287057c1d450624..1c0aa915ad3e86387ef8d949794eda090222b175 100644 (file)
@@ -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__ ({                        \