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* CDECL
__doserrno(void)
21 return &(msvcrt_get_thread_data()->thread_doserrno
);
27 int CDECL
*_errno(void)
29 return &(msvcrt_get_thread_data()->thread_errno
);
35 errno_t CDECL
_get_doserrno(unsigned long *pValue
)
40 *pValue
= *__doserrno();
47 errno_t CDECL
_set_doserrno(unsigned long error
)
49 *__doserrno() = error
;
56 errno_t CDECL
_get_errno(int *pValue
)
68 int CDECL
_set_errno(int error
)
75 * This function sets both doserrno to the passed in OS error code
76 * and also maps this to an appropriate errno code. The mapping
77 * has been deduced automagically by running this functions, which
78 * exists in MSVCRT but is undocumented, on all the error codes in
81 void CDECL
_dosmaperr(unsigned long oserror
)
85 _set_doserrno(oserror
);
87 /* Use binary chop to find the corresponding errno code */
88 for (base
=0, lim
=sizeof(doserrmap
)/sizeof(doserrmap
[0]); lim
; lim
>>= 1) {
89 pos
= base
+(lim
>> 1);
90 if (doserrmap
[pos
].winerr
== oserror
) {
91 _set_errno(doserrmap
[pos
].en
);
93 } else if (doserrmap
[pos
].winerr
< oserror
) {
98 /* EINVAL appears to be the default */
102 /******************************************************************************
103 * _set_error_mode (MSVCRT.@)
105 * Set the error mode, which describes where the C run-time writes error
109 * mode - the new error mode
112 * The old error mode.
115 int msvcrt_error_mode
= MSVCRT__OUT_TO_DEFAULT
;
117 int CDECL
_set_error_mode(int mode
)
119 const int old
= msvcrt_error_mode
;
120 if ( MSVCRT__REPORT_ERRMODE
!= mode
) {
121 msvcrt_error_mode
= mode
;
126 /******************************************************************************
127 * _seterrormode (MSVCRT.@)
129 void CDECL
_seterrormode(int mode
)
131 SetErrorMode( mode
);
134 /******************************************************************************
135 * _invalid_parameter (MSVCRT.@)
137 void CDECL
_invalid_parameter(const wchar_t *expr
, const wchar_t *func
,
138 const wchar_t *file
, unsigned int line
, uintptr_t arg
)
140 if (invalid_parameter_handler
) invalid_parameter_handler( expr
, func
, file
, line
, arg
);
143 ERR( "%s:%u %s: %s %lx\n", debugstr_w(file
), line
, debugstr_w(func
), debugstr_w(expr
), arg
);
144 RaiseException( STATUS_INVALID_CRUNTIME_PARAMETER
, EXCEPTION_NONCONTINUABLE
, 0, NULL
);
148 /* _get_invalid_parameter_handler - not exported in native msvcrt, added in msvcr80 */
149 _invalid_parameter_handler CDECL
_get_invalid_parameter_handler(void)
152 return invalid_parameter_handler
;
155 /* _set_invalid_parameter_handler - not exproted in native msvcrt, added in msvcr80 */
156 _invalid_parameter_handler CDECL
_set_invalid_parameter_handler(
157 _invalid_parameter_handler handler
)
159 _invalid_parameter_handler old
= invalid_parameter_handler
;
161 TRACE("(%p)\n", handler
);
163 invalid_parameter_handler
= handler
;