X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fmacro.h;h=4595750394d8a2a5d43c68d27d46eb0d1ec55a64;hb=e627440b41bb0284e4892f7aa9d84c77972487e2;hp=19f259e4f1166c24a5acfde409cb51e17b00b284;hpb=771f19c06a9dbe19e4c3e532d901734f4b3b3a2b;p=elogind.git diff --git a/src/shared/macro.h b/src/shared/macro.h index 19f259e4f..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. @@ -9,16 +8,16 @@ Copyright 2010 Lennart Poettering systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. systemd is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + Lesser General Public License for more details. - You should have received a copy of the GNU General Public License + You should have received a copy of the GNU Lesser General Public License along with systemd; If not, see . ***/ @@ -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