mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:57:35 +00:00
LibC: Implement wmemmove
This commit is contained in:
parent
fa1208edfd
commit
05b283f552
3 changed files with 42 additions and 0 deletions
|
@ -137,6 +137,32 @@ TEST_CASE(wmemset)
|
||||||
free(buf);
|
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)
|
TEST_CASE(wcscoll)
|
||||||
{
|
{
|
||||||
// Check if wcscoll is sorting correctly. At the moment we are doing raw char comparisons,
|
// 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;
|
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* wmemchr(const wchar_t*, wchar_t, size_t);
|
||||||
wchar_t* wmemcpy(wchar_t*, const 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* wmemset(wchar_t*, wchar_t, size_t);
|
||||||
|
wchar_t* wmemmove(wchar_t*, const wchar_t*, size_t);
|
||||||
|
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue