Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ANSI srting to utf-8 in arguments. #1443

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ int main(int argc, char **argv) {
int workers_len;
int num_cores;

#ifdef _WIN32
UINT cp = GetACP();
char **tmp_argv = alloca(argc * sizeof(wchar_t*)), *tmp;
for (i = 1; i < argc; i++) {
int len = strlen(argv[i]);
size_t pwcl = MultiByteToWideChar(cp, 0, argv[i], len, NULL, 0);
wchar_t* pwcs = (wchar_t*) malloc(sizeof(wchar_t) * (pwcl + 1));
if (pwcs == NULL) continue;
pwcl = MultiByteToWideChar(cp, 0, argv[i], len, pwcs, pwcl + 1);
pwcs[pwcl] = '\0';
size_t pmbl = WideCharToMultiByte(CP_UTF8, 0, pwcs, -1, NULL, 0, NULL, NULL);
char* pmbs = (char*) malloc(sizeof(char) * (pmbl + 1));
if (pmbs == NULL) continue;
pmbl = WideCharToMultiByte(CP_UTF8, 0, pwcs, pwcl, pmbs, pmbl, NULL, NULL);
pmbs[pmbl] = '\0';
free(pwcs);
argv[i] = pmbs;
}
#endif

#ifdef HAVE_PLEDGE
if (pledge("stdio rpath proc exec", NULL) == -1) {
die("pledge: %s", strerror(errno));
Expand Down