Hacker News new | ask | show | jobs
by heftig 787 days ago
`wcstombs` and `mbstowcs` sound like they might do this?

They're C99 standard functions and should be converting between "wide strings" and "multibyte strings", which should be native UTF-16 and UTF-8 if your current locale is an UTF-8 locale.

Apparently this works on Windows since Windows 10 version 1803 (April 2018).

There are also "restartable" variants `wcsrtombs` and `mbsrtowcs` where the conversion state is explicitly stored, instead of (presumably) a thread-local variable.

C11 added "secure" variants (with an `_s` suffix) of all these which check the destination buffer size and have different return values.