X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Futil.h;h=0246dfd826c40d417e95ac4d1630db61a09f1e31;hb=c4326aa4af424ada8ab9e6fe77035db1cf222ffa;hp=17ffd19f55415cfc0c4759021df1d442c14f3fe2;hpb=ab94af9201496ea3aa59bbf2a01eb750fbd1c08a;p=elogind.git diff --git a/src/shared/util.h b/src/shared/util.h index 17ffd19f5..0246dfd82 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -59,6 +59,17 @@ typedef struct dual_timestamp { #define USEC_PER_MONTH (2629800ULL*USEC_PER_SEC) #define USEC_PER_YEAR (31557600ULL*USEC_PER_SEC) +/* + * 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) );}) + /* What is interpreted as whitespace? */ #define WHITESPACE " \t\n\r" #define NEWLINE "\n\r"