[PATCH 1/6] defs.h: Add offsetofend macro

Eugene Syromyatnikov evgsyr at gmail.com
Sat Oct 15 19:40:28 UTC 2016


Analogous to offsetof but returns structure offset after the specified
field. Useful for checking whether specific field is present in obtained
data or specify amount of data to copy based on the (last) field needed.

* defs.h: Add offsetofend macro.
---
 defs.h |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/defs.h b/defs.h
index 2b4118b..758fd8b 100644
--- a/defs.h
+++ b/defs.h
@@ -68,6 +68,11 @@ const char *strerror(int);
 extern char *stpcpy(char *dst, const char *src);
 #endif
 
+#ifndef offsetofend
+# define offsetofend(type, member) \
+	(offsetof(type, member) + sizeof(((type *)NULL)->member))
+#endif
+
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
 
 /* macros */
-- 
1.7.10.4





More information about the Strace-devel mailing list