]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: compiler: introduce offsetoff().
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 24 Jan 2018 17:17:06 +0000 (18:17 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 5 Feb 2018 13:24:50 +0000 (14:24 +0100)
Add a offsetof() macro, if it is no there already.

include/common/compiler.h

index a13aad5c62f4e9e9280c5fead65f36a79788007a..125c4739977e0523edced7c49c6b23a20899565b 100644 (file)
 #endif
 #endif
 
+#ifndef __GNUC_PREREQ__
+#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
+#define __GNUC_PREREQ__(ma, mi) \
+        (__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))
+#else
+#define __GNUC_PREREQ__(ma, mi) 0
+#endif
+#endif
+
+#ifndef offsetof
+#if __GNUC_PREREQ__(4, 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
+
 
 #endif /* _COMMON_COMPILER_H */