1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:24:57 +00:00

LibC: Implement wmemset

This commit is contained in:
Tim Schumacher 2021-09-22 10:22:24 +00:00 committed by Brian Gianforcaro
parent 485c0ef691
commit fa1208edfd
3 changed files with 33 additions and 0 deletions

View file

@ -114,6 +114,29 @@ TEST_CASE(wmemcpy)
EXPECT_EQ(memcmp(buf, input, 8 * sizeof(wchar_t)), 0);
}
TEST_CASE(wmemset)
{
auto buf_length = 8;
auto buf = static_cast<wchar_t*>(calloc(buf_length, sizeof(wchar_t)));
if (!buf) {
FAIL("Could not allocate memory for target buffer");
return;
}
wchar_t* ret = wmemset(buf, L'\U0001f41e', buf_length - 1);
EXPECT_EQ(ret, buf);
for (int i = 0; i < buf_length - 1; i++) {
EXPECT_EQ(buf[i], L'\U0001f41e');
}
EXPECT_EQ(buf[buf_length - 1], L'\0');
free(buf);
}
TEST_CASE(wcscoll)
{
// Check if wcscoll is sorting correctly. At the moment we are doing raw char comparisons,

View file

@ -393,4 +393,13 @@ wchar_t* wmemcpy(wchar_t* dest, const wchar_t* src, size_t n)
return dest;
}
wchar_t* wmemset(wchar_t* wcs, wchar_t wc, size_t n)
{
for (size_t i = 0; i < n; i++) {
wcs[i] = wc;
}
return wcs;
}
}

View file

@ -45,5 +45,6 @@ wchar_t* wcspbrk(const wchar_t*, const wchar_t*);
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);
__END_DECLS