1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 23:27:35 +00:00

LibC: Implement wcrtomb

This function converts a single wide character into its multibyte
representation (UTF-8 in our case). It is called from libc++'s
`std::basic_ostream<wchar_t>::flush`, which gets called at program exit
from a global destructor in order to flush `std::wcout`.
This commit is contained in:
Daniel Bertalan 2021-10-04 16:59:13 +02:00 committed by Brian Gianforcaro
parent 9c29e6cde7
commit c8367df746
3 changed files with 72 additions and 3 deletions

View file

@ -6,6 +6,7 @@
#include <AK/Assertions.h>
#include <AK/Format.h>
#include <AK/UnicodeUtils.h>
#include <errno.h>
#include <wchar.h>
@ -292,10 +293,22 @@ size_t mbrlen(const char*, size_t, mbstate_t*)
TODO();
}
size_t wcrtomb(char*, wchar_t, mbstate_t*)
size_t wcrtomb(char* s, wchar_t wc, mbstate_t*)
{
dbgln("FIXME: Implement wcrtomb()");
TODO();
if (s == nullptr)
wc = L'\0';
auto nwritten = AK::UnicodeUtils::code_point_to_utf8(wc, [&s](char byte) {
if (s != nullptr)
*s++ = byte;
});
if (nwritten < 0) {
errno = EILSEQ;
return (size_t)-1;
} else {
return nwritten;
}
}
int wcscoll(const wchar_t* ws1, const wchar_t* ws2)