From: Jérémie Galarneau Date: Fri, 5 May 2017 02:56:30 +0000 (-0400) Subject: Add the container_of() macro to macro.h X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=commitdiff_plain;h=93375aa60733caf9d30d45f4a0cff0c0394e46e9 Add the container_of() macro to macro.h Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/macros.h b/src/common/macros.h index 90849ed30..7eaf27cdf 100644 --- a/src/common/macros.h +++ b/src/common/macros.h @@ -20,6 +20,7 @@ #define _MACROS_H #include +#include #include #include @@ -58,6 +59,14 @@ void *zmalloc(size_t len) #define ARRAY_SIZE(array) (sizeof(array) / (sizeof((array)[0]))) #endif +#ifndef container_of +#define container_of(ptr, type, member) \ + ({ \ + const typeof(((type *)NULL)->member) * __ptr = (ptr); \ + (type *)((char *)__ptr - offsetof(type, member)); \ + }) +#endif + #ifndef max #define max(a, b) ((a) > (b) ? (a) : (b)) #endif