X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fmacro.h;h=4595750394d8a2a5d43c68d27d46eb0d1ec55a64;hb=ac6a4abed3e69daf6795e02fa4be1719ae6ae6ab;hp=1355aac90879ca287b4f08423287057c1d450624;hpb=5430f7f2bc7330f3088b894166bf3524a067e3d8;p=elogind.git diff --git a/src/shared/macro.h b/src/shared/macro.h index 1355aac90..459575039 100644 --- a/src/shared/macro.h +++ b/src/shared/macro.h @@ -1,7 +1,6 @@ /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ -#ifndef foomacrohfoo -#define foomacrohfoo +#pragma once /*** This file is part of systemd. @@ -45,6 +44,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 +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__ ({ \ @@ -177,5 +188,3 @@ static inline size_t IOVEC_INCREMENT(struct iovec *i, unsigned n, size_t k) { } #include "log.h" - -#endif