r21297: Remove the GTK+ tools and library from the main repository. They are now...
[Samba/ekacnet.git] / source4 / libcli / util / nt_status.h
blob3e2a126b418a1b8edafc6eb3c021eccf8943aaab
1 /*
2 Unix SMB/CIFS implementation.
3 SMB parameters and setup, plus a whole lot more.
5 Copyright (C) Andrew Tridgell 2001
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #ifndef _NT_STATUS_H
23 #define _NT_STATUS_H
25 #include <stdint.h>
27 /* the following rather strange looking definitions of NTSTATUS and WERROR
28 and there in order to catch common coding errors where different error types
29 are mixed up. This is especially important as we slowly convert Samba
30 from using BOOL for internal functions
33 #if defined(HAVE_IMMEDIATE_STRUCTURES)
34 typedef struct {uint32_t v;} NTSTATUS;
35 #define NT_STATUS(x) ((NTSTATUS) { x })
36 #define NT_STATUS_V(x) ((x).v)
37 #else
38 typedef uint32_t NTSTATUS;
39 #define NT_STATUS(x) (x)
40 #define NT_STATUS_V(x) (x)
41 #endif
43 #if defined(HAVE_IMMEDIATE_STRUCTURES)
44 typedef struct {uint32_t v;} WERROR;
45 #define W_ERROR(x) ((WERROR) { x })
46 #define W_ERROR_V(x) ((x).v)
47 #else
48 typedef uint32_t WERROR;
49 #define W_ERROR(x) (x)
50 #define W_ERROR_V(x) (x)
51 #endif
53 #define NT_STATUS_IS_OK(x) (NT_STATUS_V(x) == 0)
54 #define NT_STATUS_IS_ERR(x) ((NT_STATUS_V(x) & 0xc0000000) == 0xc0000000)
55 /* checking for DOS error mapping here is ugly, but unfortunately the
56 alternative is a very intrusive rewrite of the torture code */
57 #define NT_STATUS_EQUAL(x,y) (NT_STATUS_IS_DOS(x)||NT_STATUS_IS_DOS(y)?ntstatus_dos_equal(x,y):NT_STATUS_V(x) == NT_STATUS_V(y))
59 #define NT_STATUS_HAVE_NO_MEMORY(x) do { \
60 if (!(x)) {\
61 return NT_STATUS_NO_MEMORY;\
63 } while (0)
65 #define NT_STATUS_IS_OK_RETURN(x) do { \
66 if (NT_STATUS_IS_OK(x)) {\
67 return x;\
69 } while (0)
71 #define NT_STATUS_NOT_OK_RETURN(x) do { \
72 if (!NT_STATUS_IS_OK(x)) {\
73 return x;\
75 } while (0)
77 #define NT_STATUS_IS_ERR_RETURN(x) do { \
78 if (NT_STATUS_IS_ERR(x)) {\
79 return x;\
81 } while (0)
83 #define NT_STATUS_NOT_ERR_RETURN(x) do { \
84 if (!NT_STATUS_IS_ERR(x)) {\
85 return x;\
87 } while (0)
89 #define W_ERROR_IS_OK(x) (W_ERROR_V(x) == 0)
90 #define W_ERROR_EQUAL(x,y) (W_ERROR_V(x) == W_ERROR_V(y))
92 #define W_ERROR_HAVE_NO_MEMORY(x) do { \
93 if (!(x)) {\
94 return WERR_NOMEM;\
96 } while (0)
98 #define W_ERROR_IS_OK_RETURN(x) do { \
99 if (W_ERROR_IS_OK(x)) {\
100 return x;\
102 } while (0)
104 #define W_ERROR_NOT_OK_RETURN(x) do { \
105 if (!W_ERROR_IS_OK(x)) {\
106 return x;\
108 } while (0)
110 /* this defines special NTSTATUS codes to represent DOS errors. I
111 have chosen this macro to produce status codes in the invalid
112 NTSTATUS range */
113 #define NT_STATUS_DOS(class, code) NT_STATUS(0xF1000000 | ((class)<<16) | code)
114 #define NT_STATUS_IS_DOS(status) ((NT_STATUS_V(status) & 0xFF000000) == 0xF1000000)
115 #define NT_STATUS_DOS_CLASS(status) ((NT_STATUS_V(status) >> 16) & 0xFF)
116 #define NT_STATUS_DOS_CODE(status) (NT_STATUS_V(status) & 0xFFFF)
118 /* define ldap error codes as NTSTATUS codes */
119 #define NT_STATUS_LDAP(code) NT_STATUS(0xF2000000 | code)
120 #define NT_STATUS_IS_LDAP(status) ((NT_STATUS_V(status) & 0xFF000000) == 0xF2000000)
121 #define NT_STATUS_LDAP_CODE(status) (NT_STATUS_V(status) & ~0xFF000000)
123 #endif