X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fmacro.h;h=1c0aa915ad3e86387ef8d949794eda090222b175;hb=ac7019f33f1618f5b69ed44a8623e2596f1e3856;hp=1355aac90879ca287b4f08423287057c1d450624;hpb=5430f7f2bc7330f3088b894166bf3524a067e3d8;p=elogind.git diff --git a/src/shared/macro.h b/src/shared/macro.h index 1355aac90..1c0aa915a 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__ ({ \