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
26 #define WIN32_NO_STATUS
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.
41 * status [I] Nt error code to map.
44 * The mapped Win32 error code, or ERROR_MR_MID_NOT_FOUND if there is no
47 ULONG WINAPI
RtlNtStatusToDosErrorNoTeb( NTSTATUS status
)
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
);
66 /**************************************************************************
67 * RtlNtStatusToDosError (NTDLL.@)
69 * Convert an NTSTATUS code to a Win32 error code.
72 * status [I] Nt error code to map.
75 * The mapped Win32 error code, or ERROR_MR_MID_NOT_FOUND if there is no
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.
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.
117 * err [I] The new error value to set
122 void WINAPI
RtlSetLastWin32Error( DWORD err
)
124 NtCurrentTeb()->LastErrorValue
= err
;
127 /***********************************************************************
128 * RtlSetLastWin32ErrorAndNtStatusFromNtStatus (NTDLL.@)
130 * Set the per-thread status and error values.
133 * err [I] The new status value to set
138 void WINAPI
RtlSetLastWin32ErrorAndNtStatusFromNtStatus( NTSTATUS status
)
140 NtCurrentTeb()->LastErrorValue
= RtlNtStatusToDosError( status
);