1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00
falk-werner_webfuse-provider/lib/webfuse/core/container_of.h
Falk Werner a717248e80
chore(WF_CONTAINER_OF): makes WF_CONTAINER_OF use typeof, if available (#26)
* makes WF_CONTAINER_OF use typeof, if available

* convertss WF_CONTAINER_OF to lower case

* fixes include guard
2019-04-25 20:08:34 +02:00

22 lines
472 B
C

#ifndef WF_CONTAINER_OF_H
#define WF_CONTAINER_OF_H
#ifndef __cplusplus
#include <stddef.h>
#else
#include <cstddef>
#endif
#ifdef __GNUC__
#define wf_container_of(pointer, type, member) \
({ \
const typeof( ((type *)0)->member ) * __member = (pointer); \
(type *)( (char *)__member - offsetof(type, member) ); \
})
#else
#define wf_container_of(pointer, type, member) \
(type *) (((char *) pointer) - offsetof(type, member))
#endif
#endif