include: Move ddk/imm.h to immdev.h.
[wine.git] / dlls / ntdll / error.c
blob5412b19907c098d1b58b12a662e17c1f94e19461
1 /*
2 * NTDLL error handling
4 * Copyright 2000 Alexandre Julliard
5 * Copyright 2002 Andriy Palamarchuk
6 * Copyright 2010 André Hentschel
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <stdarg.h>
25 #include "ntstatus.h"
26 #define WIN32_NO_STATUS
27 #include "windef.h"
28 #include "winternl.h"
29 #include "winerror.h"
30 #include "error.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
35 /**************************************************************************
36 * RtlNtStatusToDosErrorNoTeb (NTDLL.@)
38 * Convert an NTSTATUS code to a Win32 error code.
40 * PARAMS
41 * status [I] Nt error code to map.
43 * RETURNS
44 * The mapped Win32 error code, or ERROR_MR_MID_NOT_FOUND if there is no
45 * mapping defined.
47 ULONG WINAPI RtlNtStatusToDosErrorNoTeb( NTSTATUS status )
49 ULONG ret;
51 if (!status || (status & 0x20000000)) return status;
53 /* 0xd... is equivalent to 0xc... */
54 if ((status & 0xf0000000) == 0xd0000000) status &= ~0x10000000;
56 /* now some special cases */
57 if (HIWORD(status) == 0xc001 || HIWORD(status) == 0x8007 || HIWORD(status) == 0xc007)
58 return LOWORD( status );
60 ret = map_status( status );
61 if (ret == ERROR_MR_MID_NOT_FOUND && status != STATUS_MESSAGE_NOT_FOUND)
62 WARN( "no mapping for %08lx\n", status );
63 return ret;
66 /**************************************************************************
67 * RtlNtStatusToDosError (NTDLL.@)
69 * Convert an NTSTATUS code to a Win32 error code.
71 * PARAMS
72 * status [I] Nt error code to map.
74 * RETURNS
75 * The mapped Win32 error code, or ERROR_MR_MID_NOT_FOUND if there is no
76 * mapping defined.
78 ULONG WINAPI RtlNtStatusToDosError( NTSTATUS status )
80 NtCurrentTeb()->LastStatusValue = status;
81 return RtlNtStatusToDosErrorNoTeb( status );
84 /**********************************************************************
85 * RtlGetLastNtStatus (NTDLL.@)
87 * Get the current per-thread status.
89 NTSTATUS WINAPI RtlGetLastNtStatus(void)
91 return NtCurrentTeb()->LastStatusValue;
94 /**********************************************************************
95 * RtlGetLastWin32Error (NTDLL.@)
97 * Get the current per-thread error value set by a system function or the user.
99 * PARAMS
100 * None.
102 * RETURNS
103 * The current error value for the thread, as set by SetLastWin32Error() or SetLastError().
105 DWORD WINAPI RtlGetLastWin32Error(void)
107 return NtCurrentTeb()->LastErrorValue;
110 /***********************************************************************
111 * RtlSetLastWin32Error (NTDLL.@)
112 * RtlRestoreLastWin32Error (NTDLL.@)
114 * Set the per-thread error value.
116 * PARAMS
117 * err [I] The new error value to set
119 * RETURNS
120 * Nothing.
122 void WINAPI RtlSetLastWin32Error( DWORD err )
124 NtCurrentTeb()->LastErrorValue = err;
127 /***********************************************************************
128 * RtlSetLastWin32ErrorAndNtStatusFromNtStatus (NTDLL.@)
130 * Set the per-thread status and error values.
132 * PARAMS
133 * err [I] The new status value to set
135 * RETURNS
136 * Nothing.
138 void WINAPI RtlSetLastWin32ErrorAndNtStatusFromNtStatus( NTSTATUS status )
140 NtCurrentTeb()->LastErrorValue = RtlNtStatusToDosError( status );