libc: Implement wcstombs()
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-01-14 11:59:08 +01:00
parent 00ee8314b3
commit e3ef29e80d
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 14 additions and 0 deletions

View File

@ -110,6 +110,9 @@ extern "C"
/* Convert a multibyte character string to a wide character string. */
size_t mbstowcs(wchar_t* buf, const char* src, size_t max);
/* Convert a wide character string to a multibyte character string. */
size_t wcstombs(char* buf, const wchar_t* src, size_t max);
#ifdef __cplusplus
}
#endif

View File

@ -115,6 +115,17 @@ extern "C"
return decoder.decode(buf, max).value_or((size_t)-1);
}
size_t wcstombs(char* buf, const wchar_t* src, size_t max)
{
if (max == 0) return 0;
Utf8StringEncoder encoder(src);
if (!buf) { return encoder.byte_length().value_or((size_t)-1); }
return encoder.encode(buf, max).value_or((size_t)-1);
}
void* malloc(size_t size)
{
auto rc = malloc_impl(size);