#ifndef _NT_STATUS_H
#define _NT_STATUS_H
#ifdef _SPLINT_
#undef HAVE_IMMEDIATE_STRUCTURES
#endif
#if defined(HAVE_IMMEDIATE_STRUCTURES)
typedef struct {uint32 v;} NTSTATUS;
#define NT_STATUS(x) ((NTSTATUS) { x })
#define NT_STATUS_V(x) ((x).v)
#else
typedef uint32 NTSTATUS;
#define NT_STATUS(x) (x)
#define NT_STATUS_V(x) (x)
#endif
#if defined(HAVE_IMMEDIATE_STRUCTURES)
typedef struct {uint32 w;} WERROR;
#define W_ERROR(x) ((WERROR) { x })
#define W_ERROR_V(x) ((x).w)
#else
typedef uint32 WERROR;
#define W_ERROR(x) (x)
#define W_ERROR_V(x) (x)
#endif
#define NT_STATUS_IS_OK(x) (NT_STATUS_V(x) == 0)
#define NT_STATUS_IS_ERR(x) ((NT_STATUS_V(x) & 0xc0000000) == 0xc0000000)
#define NT_STATUS_EQUAL(x,y) (NT_STATUS_V(x) == NT_STATUS_V(y))
#define W_ERROR_IS_OK(x) (W_ERROR_V(x) == 0)
#define W_ERROR_EQUAL(x,y) (W_ERROR_V(x) == W_ERROR_V(y))
#define NT_STATUS_HAVE_NO_MEMORY(x) do { \
if (!(x)) {\
return NT_STATUS_NO_MEMORY;\
}\
} while (0)
#define NT_STATUS_NOT_OK_RETURN(x) do { \
if (!NT_STATUS_IS_OK(x)) {\
return x;\
}\
} while (0)
#define NT_STATUS_TYPE(status) ((NT_STATUS_V(status) & 0xFF000000) >> 24)
#define NT_STATUS_TYPE_DOS 0xF1
#define NT_STATUS_TYPE_LDAP 0xF2
#define NT_STATUS_DOS_MASK (NT_STATUS_TYPE_DOS << 24)
#define NT_STATUS_DOS(class, code) NT_STATUS(NT_STATUS_DOS_MASK | ((class)<<16) | code)
#define NT_STATUS_IS_DOS(status) ((NT_STATUS_V(status) & 0xFF000000) == NT_STATUS_DOS_MASK)
#define NT_STATUS_DOS_CLASS(status) ((NT_STATUS_V(status) >> 16) & 0xFF)
#define NT_STATUS_DOS_CODE(status) (NT_STATUS_V(status) & 0xFFFF)
#define NT_STATUS_LDAP_MASK (NT_STATUS_TYPE_LDAP << 24)
#define NT_STATUS_LDAP(code) NT_STATUS(NT_STATUS_LDAP_MASK | code)
#define NT_STATUS_IS_LDAP(status) ((NT_STATUS_V(status) & 0xFF000000) == NT_STATUS_LDAP_MASK)
#define NT_STATUS_LDAP_CODE(status) (NT_STATUS_V(status) & ~0xFF000000)
#endif