diff options
author | kib <kib@FreeBSD.org> | 2008-06-16 17:25:20 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2008-06-16 17:25:20 +0000 |
commit | 4c48f0aa48a663c0fbd8b13ab1334deff50098f0 (patch) | |
tree | 59478baebb585b0fb9af136c946231a780ff3176 | |
parent | 64a55bfcba978b422db8506f56ae867876e99565 (diff) | |
download | FreeBSD-src-4c48f0aa48a663c0fbd8b13ab1334deff50098f0.zip FreeBSD-src-4c48f0aa48a663c0fbd8b13ab1334deff50098f0.tar.gz |
Add the member2struct() macro, that returns pointer to the containing
structure given pointer to some structure member.
MFC after: 2 weeks
-rw-r--r-- | sys/sys/param.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/sys/sys/param.h b/sys/sys/param.h index 98d153a..8b19a64 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -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_ */ |