libc: Implement wcstombs()
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
00ee8314b3
commit
e3ef29e80d
@ -110,6 +110,9 @@ extern "C"
|
|||||||
/* Convert a multibyte character string to a wide character string. */
|
/* Convert a multibyte character string to a wide character string. */
|
||||||
size_t mbstowcs(wchar_t* buf, const char* src, size_t max);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -115,6 +115,17 @@ extern "C"
|
|||||||
return decoder.decode(buf, max).value_or((size_t)-1);
|
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)
|
void* malloc(size_t size)
|
||||||
{
|
{
|
||||||
auto rc = malloc_impl(size);
|
auto rc = malloc_impl(size);
|
||||||
|
Loading…
Reference in New Issue
Block a user