Skip to content
Snippets Groups Projects
Commit ca7b2006 authored by Anjan Chanda's avatar Anjan Chanda
Browse files

define offsetof() and container_of()

parent 67e6b91b
Branches devel
No related tags found
No related merge requests found
Pipeline #207818 passed
...@@ -14,6 +14,18 @@ ...@@ -14,6 +14,18 @@
#ifndef _HLIST_H #ifndef _HLIST_H
#define _HLIST_H #define _HLIST_H
#ifndef offsetof
#define offsetof(type, member) ((size_t) &((type *)0)->member)
#endif
#ifndef container_of
#define container_of(ptr, type, member) \
({ \
const __typeof__(((type *) NULL)->member) *__mptr = (ptr); \
(type *) ((char *) __mptr - offsetof(type, member)); \
})
#endif
struct hlist_node { struct hlist_node {
struct hlist_node *next; struct hlist_node *next;
}; };
......
...@@ -136,6 +136,14 @@ extern int get_ifoperstatus(const char *ifname, ifopstatus_t *opstatus); ...@@ -136,6 +136,14 @@ extern int get_ifoperstatus(const char *ifname, ifopstatus_t *opstatus);
#define offsetof(type, member) ((size_t) &((type *)0)->member) #define offsetof(type, member) ((size_t) &((type *)0)->member)
#endif #endif
#ifndef container_of
#define container_of(ptr, type, member) \
({ \
const __typeof__(((type *) NULL)->member) *__mptr = (ptr); \
(type *) ((char *) __mptr - offsetof(type, member)); \
})
#endif
#ifndef bit #ifndef bit
#define bit(_n) (1 << (_n)) #define bit(_n) (1 << (_n))
#endif #endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment