From 0ea48e79fc9c7e8779f1ca1434cde7191e41930e Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Sun, 14 Apr 2024 20:00:40 +0300 Subject: [PATCH] [CRT] Move _invalid_parameter into its own file As the author of the code, I changed to license to MIT. --- sdk/lib/crt/stdlib/_invalid_parameter.c | 52 +++++++++++++++++++++++++ sdk/lib/crt/stdlib/errno.c | 37 ------------------ sdk/lib/crt/stdlib/stdlib.cmake | 1 + 3 files changed, 53 insertions(+), 37 deletions(-) create mode 100644 sdk/lib/crt/stdlib/_invalid_parameter.c diff --git a/sdk/lib/crt/stdlib/_invalid_parameter.c b/sdk/lib/crt/stdlib/_invalid_parameter.c new file mode 100644 index 00000000000..dd9b45cd706 --- /dev/null +++ b/sdk/lib/crt/stdlib/_invalid_parameter.c @@ -0,0 +1,52 @@ +/* + * PROJECT: ReactOS CRT library + * LICENSE: MIT (https://spdx.org/licenses/MIT) + * PURPOSE: _invalid_parameter implementation + * COPYRIGHT: Timo Kreuzer + */ + +#include + +#ifdef _MSVCRTEX_ +#undef TRACE +#undef ERR +#define TRACE(...) +#define ERR(...) +#endif + +static _invalid_parameter_handler invalid_parameter_handler = NULL; + +/****************************************************************************** + * _invalid_parameter (MSVCRT.@) + */ +void __cdecl _invalid_parameter(const wchar_t *expr, const wchar_t *func, + const wchar_t *file, unsigned int line, uintptr_t arg) +{ + if (invalid_parameter_handler) invalid_parameter_handler( expr, func, file, line, arg ); + else + { + ERR( "%s:%u %s: %s %lx\n", debugstr_w(file), line, debugstr_w(func), debugstr_w(expr), arg ); +#if _MSVCR_VER > 0 // FIXME: possible improvement: use a global variable in the DLL + RaiseException( STATUS_INVALID_CRUNTIME_PARAMETER, EXCEPTION_NONCONTINUABLE, 0, NULL ); +#endif + } +} + +/* _get_invalid_parameter_handler - not exported in native msvcrt, added in msvcr80 */ +_invalid_parameter_handler CDECL _get_invalid_parameter_handler(void) +{ + TRACE("\n"); + return invalid_parameter_handler; +} + +/* _set_invalid_parameter_handler - not exproted in native msvcrt, added in msvcr80 */ +_invalid_parameter_handler CDECL _set_invalid_parameter_handler( + _invalid_parameter_handler handler) +{ + _invalid_parameter_handler old = invalid_parameter_handler; + + TRACE("(%p)\n", handler); + + invalid_parameter_handler = handler; + return old; +} diff --git a/sdk/lib/crt/stdlib/errno.c b/sdk/lib/crt/stdlib/errno.c index a59032bb3f9..55bcb60d8f0 100644 --- a/sdk/lib/crt/stdlib/errno.c +++ b/sdk/lib/crt/stdlib/errno.c @@ -11,8 +11,6 @@ #include #include -static _invalid_parameter_handler invalid_parameter_handler = NULL; - /********************************************************************* * _errno (MSVCRT.@) */ @@ -130,38 +128,3 @@ void CDECL _seterrormode(int mode) { SetErrorMode( mode ); } - -/****************************************************************************** - * _invalid_parameter (MSVCRT.@) - */ -void __cdecl _invalid_parameter(const wchar_t *expr, const wchar_t *func, - const wchar_t *file, unsigned int line, uintptr_t arg) -{ - if (invalid_parameter_handler) invalid_parameter_handler( expr, func, file, line, arg ); - else - { - ERR( "%s:%u %s: %s %lx\n", debugstr_w(file), line, debugstr_w(func), debugstr_w(expr), arg ); -#if _MSVCR_VER > 0 // FIXME: possible improvement: use a global variable in the DLL - RaiseException( STATUS_INVALID_CRUNTIME_PARAMETER, EXCEPTION_NONCONTINUABLE, 0, NULL ); -#endif - } -} - -/* _get_invalid_parameter_handler - not exported in native msvcrt, added in msvcr80 */ -_invalid_parameter_handler CDECL _get_invalid_parameter_handler(void) -{ - TRACE("\n"); - return invalid_parameter_handler; -} - -/* _set_invalid_parameter_handler - not exproted in native msvcrt, added in msvcr80 */ -_invalid_parameter_handler CDECL _set_invalid_parameter_handler( - _invalid_parameter_handler handler) -{ - _invalid_parameter_handler old = invalid_parameter_handler; - - TRACE("(%p)\n", handler); - - invalid_parameter_handler = handler; - return old; -} diff --git a/sdk/lib/crt/stdlib/stdlib.cmake b/sdk/lib/crt/stdlib/stdlib.cmake index ba493f3f919..e4680908d14 100644 --- a/sdk/lib/crt/stdlib/stdlib.cmake +++ b/sdk/lib/crt/stdlib/stdlib.cmake @@ -11,6 +11,7 @@ list(APPEND LIBCNTPR_STDLIB_SOURCE list(APPEND CRT_STDLIB_SOURCE ${COMMON_STDLIB_SOURCE} stdlib/_exit.c + stdlib/_invalid_parameter.c stdlib/_set_abort_behavior.c stdlib/abort.c stdlib/atexit.c