Create process with wide chars on Windows

Windows does not support UTF-8, so pushing a file with non-ASCII
characters failed.

Convert the UTF-8 command line to a wide characters string and call
CreateProcessW().

Fixes <https://github.com/Genymobile/scrcpy/issues/422>
This commit is contained in:
Romain Vimont
2019-02-10 12:53:03 +01:00
parent c0b65b14df
commit 477c0a2cab
3 changed files with 40 additions and 2 deletions

View File

@@ -3,6 +3,11 @@
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
# include <windows.h>
# include <tchar.h>
#endif
size_t xstrncpy(char *dest, const char *src, size_t n) {
size_t i;
for (i = 0; i < n - 1 && src[i] != '\0'; ++i)
@@ -47,3 +52,22 @@ char *strquote(const char *src) {
quoted[len + 2] = '\0';
return quoted;
}
#ifdef _WIN32
wchar_t *utf8_to_wide_char(const char *utf8) {
int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
if (!len) {
return NULL;
}
wchar_t *wide = malloc(len * sizeof(wchar_t));
if (!wide) {
return NULL;
}
MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wide, len);
return wide;
}
#endif