mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 19:19:44 +03:00
LibC: Implement wmemmove
This commit is contained in:
parent
fa1208edfd
commit
05b283f552
Notes:
sideshowbarker
2024-07-18 05:37:06 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/05b283f552b Pull-request: https://github.com/SerenityOS/serenity/pull/10298 Reviewed-by: https://github.com/bgianfo ✅
@ -137,6 +137,32 @@ TEST_CASE(wmemset)
|
||||
free(buf);
|
||||
}
|
||||
|
||||
TEST_CASE(wmemmove)
|
||||
{
|
||||
wchar_t* ret;
|
||||
const wchar_t* string = L"abc\0def";
|
||||
auto buf = static_cast<wchar_t*>(calloc(32, sizeof(wchar_t)));
|
||||
|
||||
if (!buf) {
|
||||
FAIL("Could not allocate memory for target buffer");
|
||||
return;
|
||||
}
|
||||
|
||||
// Test moving to smaller addresses.
|
||||
wmemcpy(buf + 3, string, 8);
|
||||
ret = wmemmove(buf + 1, buf + 3, 8);
|
||||
EXPECT_EQ(ret, buf + 1);
|
||||
EXPECT_EQ(memcmp(string, buf + 1, 8 * sizeof(wchar_t)), 0);
|
||||
|
||||
// Test moving to larger addresses.
|
||||
wmemcpy(buf + 16, string, 8);
|
||||
ret = wmemmove(buf + 18, buf + 16, 8);
|
||||
EXPECT_EQ(ret, buf + 18);
|
||||
EXPECT_EQ(memcmp(string, buf + 18, 8 * sizeof(wchar_t)), 0);
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
TEST_CASE(wcscoll)
|
||||
{
|
||||
// Check if wcscoll is sorting correctly. At the moment we are doing raw char comparisons,
|
||||
|
@ -402,4 +402,19 @@ wchar_t* wmemset(wchar_t* wcs, wchar_t wc, size_t n)
|
||||
|
||||
return wcs;
|
||||
}
|
||||
|
||||
wchar_t* wmemmove(wchar_t* dest, const wchar_t* src, size_t n)
|
||||
{
|
||||
if (dest > src) {
|
||||
for (size_t i = 1; i <= n; i++) {
|
||||
dest[n - i] = src[n - i];
|
||||
}
|
||||
} else if (dest < src) {
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
dest[i] = src[i];
|
||||
}
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
@ -46,5 +46,6 @@ wchar_t* wcsstr(const wchar_t*, const wchar_t*);
|
||||
wchar_t* wmemchr(const wchar_t*, wchar_t, size_t);
|
||||
wchar_t* wmemcpy(wchar_t*, const wchar_t*, size_t);
|
||||
wchar_t* wmemset(wchar_t*, wchar_t, size_t);
|
||||
wchar_t* wmemmove(wchar_t*, const wchar_t*, size_t);
|
||||
|
||||
__END_DECLS
|
||||
|
Loading…
Reference in New Issue
Block a user