]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include/list, include/c: update and container_of()
authorKarel Zak <kzak@redhat.com>
Fri, 20 Jul 2018 13:22:35 +0000 (15:22 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 20 Jul 2018 13:22:35 +0000 (15:22 +0200)
* update container_of() to version without "const" qualifier

* use container_of() in list_entry()

Signed-off-by: Karel Zak <kzak@redhat.com>
include/c.h
include/list.h

index c8bcb375b27b012a532e19e8ce3d7f1c2ca1d67d..a240f4f6c506ec578bc8a5c598b44d2ecb836edc 100644 (file)
 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
 #endif
 
+/*
+ * container_of - cast a member of a structure out to the containing structure
+ * @ptr:       the pointer to the member.
+ * @type:      the type of the container struct this is embedded in.
+ * @member:    the name of the member within the struct.
+ */
 #ifndef container_of
-#define container_of(ptr, type, member) __extension__ ({        \
-       const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
-       (type *)( (char *)__mptr - offsetof(type,member) );})
+#define container_of(ptr, type, member) __extension__ ({       \
+       void *__mptr = (void *)(ptr);                           \
+       ((type *)(__mptr - offsetof(type, member))); })
 #endif
 
 #ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME
index cf022fb22529b067ba9597d757be4ea752f8a28f..f3ffc79859a3366db55013fb508301351fd7013d 100644 (file)
@@ -12,6 +12,8 @@
 #ifndef UTIL_LINUX_LIST_H
 #define UTIL_LINUX_LIST_H
 
+#include "c.h"
+
 /* TODO: use AC_C_INLINE */
 #ifdef __GNUC__
 #define _INLINE_ static __inline__
@@ -161,10 +163,7 @@ _INLINE_ void list_splice(struct list_head *list, struct list_head *head)
  * @type:      the type of the struct this is embedded in.
  * @member:    the name of the list_struct within the struct.
  */
-#define list_entry(ptr, type, member) __extension__ ({              \
-       const typeof( ((type *)0)->member ) *__mptr = (ptr);   \
-       (type *)( (char *)__mptr - offsetof(type,member) );})
-
+#define list_entry(ptr, type, member)  container_of(ptr, type, member)
 
 #define list_first_entry(head, type, member) \
        ((head) && (head)->next != (head) ? list_entry((head)->next, type, member) : NULL)