2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/crt/errno.c
10 #include "doserrmap.h"
12 #include <internal/wine/msvcrt.h>
14 static _invalid_parameter_handler invalid_parameter_handler
= NULL
;
19 unsigned long* __doserrno(void)
21 return (unsigned long*)(&GetThreadData()->tdoserrno
);
29 return(&GetThreadData()->terrno
);
33 int __set_doserrno(int error
)
35 PTHREADDATA ThreadData
;
37 ThreadData
= GetThreadData();
39 ThreadData
->tdoserrno
= error
;
44 int __set_errno(int error
)
46 PTHREADDATA ThreadData
;
48 ThreadData
= GetThreadData();
50 ThreadData
->terrno
= error
;
56 * This function sets both doserrno to the passed in OS error code
57 * and also maps this to an appropriate errno code. The mapping
58 * has been deduced automagically by running this functions, which
59 * exists in MSVCRT but is undocumented, on all the error codes in
62 void _dosmaperr(unsigned long oserror
)
66 __set_doserrno(oserror
);
68 /* Use binary chop to find the corresponding errno code */
69 for (base
=0, lim
=sizeof(doserrmap
)/sizeof(doserrmap
[0]); lim
; lim
>>= 1) {
70 pos
= base
+(lim
>> 1);
71 if (doserrmap
[pos
].winerr
== oserror
) {
72 __set_errno(doserrmap
[pos
].en
);
74 } else if (doserrmap
[pos
].winerr
< oserror
) {
79 /* EINVAL appears to be the default */
83 /******************************************************************************
84 * _set_error_mode (MSVCRT.@)
86 * Set the error mode, which describes where the C run-time writes error
90 * mode - the new error mode
96 * This function does not have a proper implementation; the error mode is
99 int CDECL
_set_error_mode(int mode
)
101 static int current_mode
= MSVCRT__OUT_TO_DEFAULT
;
103 const int old
= current_mode
;
104 if ( MSVCRT__REPORT_ERRMODE
!= mode
) {
111 /******************************************************************************
112 * _seterrormode (MSVCRT.@)
114 void CDECL
_seterrormode(int mode
)
116 SetErrorMode( mode
);
119 /******************************************************************************
120 * _invalid_parameter (MSVCRT.@)
122 void __cdecl
_invalid_parameter(const wchar_t *expr
, const wchar_t *func
,
123 const wchar_t *file
, unsigned int line
, uintptr_t arg
)
125 if (invalid_parameter_handler
) invalid_parameter_handler( expr
, func
, file
, line
, arg
);
128 ERR( "%s:%u %s: %s %lx\n", debugstr_w(file
), line
, debugstr_w(func
), debugstr_w(expr
), arg
);
129 RaiseException( STATUS_INVALID_CRUNTIME_PARAMETER
, EXCEPTION_NONCONTINUABLE
, 0, NULL
);
133 /* _get_invalid_parameter_handler - not exported in native msvcrt, added in msvcr80 */
134 _invalid_parameter_handler CDECL
_get_invalid_parameter_handler(void)
137 return invalid_parameter_handler
;
140 /* _set_invalid_parameter_handler - not exproted in native msvcrt, added in msvcr80 */
141 _invalid_parameter_handler CDECL
_set_invalid_parameter_handler(
142 _invalid_parameter_handler handler
)
144 _invalid_parameter_handler old
= invalid_parameter_handler
;
146 TRACE("(%p)\n", handler
);
148 invalid_parameter_handler
= handler
;