Add the member2struct() macro, that returns pointer to the containing

structure given pointer to some structure member.

MFC after:	2 weeks
This commit is contained in:
Konstantin Belousov 2008-06-16 17:25:20 +00:00
parent a1dba0f9f4
commit 4c20b7670c

View File

@ -305,4 +305,11 @@ __END_DECLS
#define ctodb(db) /* calculates pages to devblks */ \
((db) << (PAGE_SHIFT - DEV_BSHIFT))
/*
* Given the pointer x to the member m of the struct s, return
* a pointer to the containing structure.
*/
#define member2struct(s, m, x) \
((struct s *)(void *)((char *)(x) - offsetof(struct s, m)))
#endif /* _SYS_PARAM_H_ */