From 1a056d24a79242db09963dd0b0c2193c5034b61b Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Sat, 22 Oct 2011 09:45:10 +0100 Subject: [PATCH] opr: Add opr_containerof Add the opr_containerof macro, which can be used to find the base address of a structure which contains a member whose location is known. This formulation is heavily used throughout OpenAFS to determine the base address of structures containing queue pointers - this provides a central definition, rather than coding it from scratch each time. Change-Id: I2a32a214252ad304238f740ad92579e5bb7287be Reviewed-on: http://gerrit.openafs.org/5836 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/opr/opr.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/opr/opr.h b/src/opr/opr.h index b53211c..d7db2cc 100644 --- a/src/opr/opr.h +++ b/src/opr/opr.h @@ -1,7 +1,13 @@ #ifndef OPENAFS_OPR_OPR_H #define OPENAFS_OPR_OPR_H 1 +/* macros */ + +#define opr_containerof(ptr, structure, member) \ + ((structure *)((char *)(ptr)-(char *)(&((structure *)NULL)->member))) + /* assert.c */ + #ifdef AFS_NT40_ENV # define opr_abort() opr_NTAbort() extern void opr_NTAbort(void); -- 1.9.4