xen/include: import sizeof_field() macro from Linux stddef.h
authorPaul Durrant <pdurrant@amazon.com>
Wed, 25 Nov 2020 13:06:27 +0000 (14:06 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 25 Nov 2020 13:06:27 +0000 (14:06 +0100)
Co-locate it with the definition of offsetof() (since this is also in stddef.h
in the Linux kernel source). This macro will be needed in a subsequent patch.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
xen/include/xen/compiler.h

index c0e0ee9f27be1807bb2112576c68f36ae04e7753..676c6ea1b0a037e0759fdb39eddaf8a4716f47c8 100644 (file)
 
 #define offsetof(a,b) __builtin_offsetof(a,b)
 
+/**
+ * sizeof_field(TYPE, MEMBER)
+ *
+ * @TYPE: The structure containing the field of interest
+ * @MEMBER: The field to return the size of
+ */
+#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
+
 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
 #define alignof __alignof__
 #endif