Hi Phillip,
welcome back!
Does this baroque solution based on the "Think positive!" motto satisfy
you? :)
Emanuele
#include <all_inclusive.h>
#define CLEANUP_DEFINE DWORD __FUNCTION__##__cleanup_mask = 0
#define CLEANUP_SET(f) __FUNCTION__##__cleanup_mask != (m)
#define CLEANUP_DO(m,f) if (__FUNCTION__##__cleanup_mask & (m)) (f)
#define CLEANUP_BIT(b) (1<<(b))
NSTATUS DoSomething()
{
NSTATUS Status = STATUS_SUCCESS;
CLEANUP_DEFINE;
#define MASK_XXX CLEANUP_BIT(1)
#define MASK_YYY CLEANUP_BIT(2)
#define MASK_ZZZ CLEANUP_BIT(3)
...
Status = NtXXX();
if (NT_SUCCESS(Status))
{
CLEANUP_SET(MASK_XXX);
Status = NtYYY();
if (NT_SUCCESS(Status))
{
CLEANUP_SET(MASK_YYY);
Status = NtZZZ();
if (NT_SUCCESS(Status))
{
CLEANUP_SET(MASK_ZZZ);
// yay, everything worked
}
}
}
CLEANUP_DO(MASK_ZZZ,cleanupZZZ);
CLEANUP_DO(MASK_YYY,cleanupYYY);
CLEANUP_DO(MASK_XXX,cleanupXXX);
return Status;
}
/* EOF */