From f46e239468d48cf984cb8dc6697be840345199db Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Fri, 13 Nov 2020 13:18:53 +0100 Subject: [PATCH] kernelbase: Copy MulDiv() implementation instead of forwarding. Signed-off-by: Alexandre Julliard --- dlls/kernelbase/kernelbase.spec | 2 +- dlls/kernelbase/main.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/dlls/kernelbase/kernelbase.spec b/dlls/kernelbase/kernelbase.spec index da35b5e5c6e..36d0492857f 100644 --- a/dlls/kernelbase/kernelbase.spec +++ b/dlls/kernelbase/kernelbase.spec @@ -959,7 +959,7 @@ @ stdcall MoveFileExW(wstr wstr long) # @ stub MoveFileWithProgressTransactedW @ stdcall MoveFileWithProgressW(wstr wstr ptr ptr long) -@ stdcall MulDiv(long long long) kernel32.MulDiv +@ stdcall MulDiv(long long long) @ stdcall MultiByteToWideChar(long long str long ptr long) # @ stub NamedPipeEventEnum # @ stub NamedPipeEventSelect diff --git a/dlls/kernelbase/main.c b/dlls/kernelbase/main.c index e85586a0751..b90ee1cba2c 100644 --- a/dlls/kernelbase/main.c +++ b/dlls/kernelbase/main.c @@ -62,6 +62,32 @@ BOOL WINAPI DllMainCRTStartup( HANDLE inst, DWORD reason, LPVOID reserved ) } +/*********************************************************************** + * MulDiv (kernelbase.@) + */ +INT WINAPI MulDiv( INT a, INT b, INT c ) +{ + LONGLONG ret; + + if (!c) return -1; + + /* We want to deal with a positive divisor to simplify the logic. */ + if (c < 0) + { + a = -a; + c = -c; + } + + /* If the result is positive, we "add" to round. else, we subtract to round. */ + if ((a < 0 && b < 0) || (a >= 0 && b >= 0)) + ret = (((LONGLONG)a * b) + (c / 2)) / c; + else + ret = (((LONGLONG)a * b) - (c / 2)) / c; + + if (ret > 2147483647 || ret < -2147483647) return -1; + return ret; +} + /*********************************************************************** * AppPolicyGetProcessTerminationMethod (KERNELBASE.@) */