]> git.ozlabs.org Git - ccan/commit
container_of: Add container_of_or_null()
authorDavid Gibson <david@gibson.dropbear.id.au>
Tue, 9 Sep 2014 14:22:52 +0000 (00:22 +1000)
committerRusty Russell <rusty@rustcorp.com.au>
Sat, 13 Sep 2014 05:41:38 +0000 (15:11 +0930)
commit7ec5b8e06b2fd5fa98b1fcde1158c286d2d429d8
tree78f3d797e711a0d29786aed843c62505648c1df7
parentf3c92802bfdb388f8c191cd1c682f90bc485b357
container_of: Add container_of_or_null()

It's quite common to have a pointer which could be either a pointer to a
structure member, or NULL.  This needs special casing with container_of(),
or it will convert NULL into something strange.

This patch adds container_of_or_null(), which will return NULL if passed
(an appropriately typed) NULL, or the containining structure as
container_of() otherwise.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/container_of/container_of.h
ccan/container_of/test/run.c