Add functions to convert wide char to UTF-8
There was already utf8_to_wide_char(), used to correctly execute commands on Windows. Add the reverse converter: utf8_from_wide_char(). We will need it to build the scrcpy-server path based on the executable directory.
This commit is contained in:
@@ -92,4 +92,20 @@ utf8_to_wide_char(const char *utf8) {
|
||||
return wide;
|
||||
}
|
||||
|
||||
char *
|
||||
utf8_from_wide_char(const wchar_t *ws) {
|
||||
int len = WideCharToMultiByte(CP_UTF8, 0, ws, -1, NULL, 0, NULL, NULL);
|
||||
if (!len) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *utf8 = SDL_malloc(len);
|
||||
if (!utf8) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
WideCharToMultiByte(CP_UTF8, 0, ws, -1, utf8, len, NULL, NULL);
|
||||
return utf8;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user