From a31da786859d8657641c5c115e8c74fcc34ec747 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sat, 13 Sep 2025 14:21:54 +0200 Subject: [PATCH] IMPORT: ebtree: add a definition of offsetof() We'll use this to improve the definition of container_of(). Let's define it if it does not exist. We can rely on __builtin_offsetof() on recent enough compilers. This is ebtree commit 1ea273e60832b98f552b9dbd013e6c2b32113aa5. Signed-off-by: Willy Tarreau This is ebtree commit 69b2ef57a8ce321e8de84486182012c954380401. --- include/import/ebtree.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/import/ebtree.h b/include/import/ebtree.h index 2506e288b..3cd3ae9be 100644 --- a/include/import/ebtree.h +++ b/include/import/ebtree.h @@ -246,6 +246,7 @@ #ifndef _EBTREE_H #define _EBTREE_H +#include #include #include #include @@ -365,6 +366,15 @@ static inline unsigned int flsnz64(unsigned long long x) #define fls64(x) flsnz64(x) #define fls_auto(x) ((x) ? flsnz(x) : 0) +/* offsetof() is provided as a builtin starting with gcc-4.1 */ +#ifndef offsetof +# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) +# define offsetof(type, field) __builtin_offsetof(type, field) +# else +# define offsetof(type, field) ((__size_t)(__uintptr_t)((const volatile void *)&((type *)0)->field)) +# endif +#endif + /* Linux-like "container_of". It returns a pointer to the structure of type * which has its member stored at address . */