[PATCH 01/21] common: Add offsetof and offsetofend macros
Benjamin Berg
benjamin at sipsolutions.net
Tue Oct 27 06:16:47 PDT 2026
From: Benjamin Berg <benjamin.berg at intel.com>
Also move the definition of offsetof into common.h as it is generally
useful.
Signed-off-by: Benjamin Berg <benjamin.berg at intel.com>
Reviewed-by: Andrei Otcheretianski <andrei.otcheretianski at intel.com>
---
src/utils/common.h | 8 ++++++++
src/utils/list.h | 6 ++----
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/utils/common.h b/src/utils/common.h
index 076f26697a..34f58daf64 100644
--- a/src/utils/common.h
+++ b/src/utils/common.h
@@ -658,4 +658,12 @@ void * __hide_aliasing_typecast(void *foo);
#define WPA_MEM_DEFINED(ptr, len) do { } while (0)
#endif /* CONFIG_VALGRIND */
+#ifndef offsetof
+#define offsetof(type, member) ((size_t) &((type *) 0)->member)
+#endif
+
+#ifndef offsetofend
+#define offsetofend(type, member) (offsetof(type, member) + sizeof(((type *) 0)->member))
+#endif
+
#endif /* COMMON_H */
diff --git a/src/utils/list.h b/src/utils/list.h
index aa62c08811..d1d896b9c2 100644
--- a/src/utils/list.h
+++ b/src/utils/list.h
@@ -9,6 +9,8 @@
#ifndef LIST_H
#define LIST_H
+#include "common.h"
+
/**
* struct dl_list - Doubly-linked list
*/
@@ -60,10 +62,6 @@ static inline unsigned int dl_list_len(const struct dl_list *list)
return count;
}
-#ifndef offsetof
-#define offsetof(type, member) ((long) &((type *) 0)->member)
-#endif
-
#define dl_list_entry(item, type, member) \
((type *) ((char *) item - offsetof(type, member)))
--
2.56.0
More information about the Hostap
mailing list