From: Simon Wilkinson Date: Sat, 22 Oct 2011 08:45:10 +0000 (+0100) Subject: opr: Add opr_containerof X-Git-Tag: upstream/1.8.0_pre1^2~3053 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=1a056d24a79242db09963dd0b0c2193c5034b61b;p=packages%2Fo%2Fopenafs.git 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 --- diff --git a/src/opr/opr.h b/src/opr/opr.h index b53211c2a..d7db2cc02 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);