]> granicus.if.org Git - strace/commitdiff
defs.h: add offsetofend macro
authorEugene Syromyatnikov <evgsyr@gmail.com>
Sat, 3 Sep 2016 11:41:33 +0000 (14:41 +0300)
committerEugene Syromyatnikov <evgsyr@gmail.com>
Wed, 26 Oct 2016 01:20:06 +0000 (04:20 +0300)
Analogous to offsetof but returns structure offset after the specified
field.  Useful for checking whether specific field is present in obtained
data or specifying amount of data to copy based on the (last) field needed.

* defs.h (offsetofend): New macro.

defs.h

diff --git a/defs.h b/defs.h
index 2b4118b5a863f710c8630734367b71c2fd4578db..758fd8b914b11c7dad2ac68d46f48a378a5757af 100644 (file)
--- 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 */