Skip to content

Commit

Permalink
Convert ANSI srting to utf-8 in arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattn committed Apr 14, 2021
1 parent a61f178 commit a76112c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@ 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';
cp = CP_UTF8;
size_t pmbl = WideCharToMultiByte(cp, 0, pwcs, -1, NULL, 0, NULL, NULL);
char* pmbs = (char*) malloc(sizeof(char) * (pmbl + 1));
if (pmbs == NULL) continue;
pmbl = WideCharToMultiByte(cp, 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

0 comments on commit a76112c

Please sign in to comment.