chiark / gitweb /
journal: align byte-buffer that gets cased to an object
[elogind.git] / src / shared / macro.h
index 1355aac90879ca287b4f08423287057c1d450624..97eebbc88be174349e31b24e36bd1db4533d2f7e 100644 (file)
@@ -45,6 +45,7 @@
 #define _hidden_ __attribute__ ((visibility("hidden")))
 #define _weakref_(x) __attribute__((weakref(#x)))
 #define _introspect_(x) __attribute__((section("introspect." x)))
+#define _alignas_(x) __attribute__((aligned(__alignof(x))))
 
 #define XSTRINGIFY(x) #x
 #define STRINGIFY(x) XSTRINGIFY(x)
@@ -57,6 +58,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__ ({                        \