mirror of https://github.com/ipxe/ipxe.git
Added container_of(). This seems about the best place to put it, since
the definition of it uses offsetof(), and the two concepts are related.pull/1/head
parent
99032becce
commit
508dcdb303
|
@ -2,12 +2,17 @@
|
||||||
#define STDDEF_H
|
#define STDDEF_H
|
||||||
|
|
||||||
/* for size_t */
|
/* for size_t */
|
||||||
#include "stdint.h"
|
#include <stdint.h>
|
||||||
|
|
||||||
#undef NULL
|
#undef NULL
|
||||||
#define NULL ((void *)0)
|
#define NULL ((void *)0)
|
||||||
|
|
||||||
#undef offsetof
|
#undef offsetof
|
||||||
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|
||||||
|
|
||||||
|
#undef container_of
|
||||||
|
#define container_of(ptr, type, member) ({ \
|
||||||
|
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
||||||
|
(type *)( (char *)__mptr - offsetof(type,member) );})
|
||||||
|
|
||||||
#endif /* STDDEF_H */
|
#endif /* STDDEF_H */
|
||||||
|
|
Loading…
Reference in New Issue