Commit a98e3e6
committed
refactor(win32): force CP_UTF8 to get rid of all wchar use except CommandLineToArgvW
See https://learn.microsoft.com/en-us/windows/apps/design/globalizing/use-utf8-code-page
But Windows doesn't provide CommandLineToArgvA() because in non-Unicode
codepage environment, the encoding conversion is lossy and it may case
security issue, so they said:
> To avoid this problem, use the GetCommandLineW function to receive the
> Unicode command line, or use an application manifest (on Windows Version 1903
> or later) to set UTF-8 as the process code page.
> https://learn.microsoft.com/en-us/windows/win32/api/processenv/nf-processenv-getcommandlinea#security-remarks
So Windows seems provide two solutions: one for legacy encoding, another
for modern Unicode encoding. It's great, right? No!!! Windows actually
only provide ONE solution! They never provide CommandLineToArgvA() at all.
So altrought I can get UTF-8 version arguments from GetCommandLineA() but
I can convert it into argv[] with UTF-8 encoding. I must pass it into
CommandLineToArgvW() to get UTF-16LE version argv[], and convert it into
UTF-8 with a annoying loop and WideCharToMultiByte(). It's crazy!!!
Signed-off-by: Coelacanthus <[email protected]>1 parent 22dcc49 commit a98e3e6
3 files changed
Lines changed: 22 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
| 44 | + | |
| 45 | + | |
48 | 46 | | |
49 | 47 | | |
50 | 48 | | |
51 | 49 | | |
52 | 50 | | |
53 | | - | |
| 51 | + | |
54 | 52 | | |
55 | 53 | | |
56 | 54 | | |
57 | 55 | | |
58 | 56 | | |
59 | | - | |
| 57 | + | |
60 | 58 | | |
61 | 59 | | |
62 | 60 | | |
63 | 61 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 62 | + | |
68 | 63 | | |
69 | 64 | | |
70 | | - | |
71 | | - | |
| 65 | + | |
| 66 | + | |
72 | 67 | | |
73 | 68 | | |
74 | 69 | | |
| |||
171 | 166 | | |
172 | 167 | | |
173 | 168 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
| 169 | + | |
| 170 | + | |
179 | 171 | | |
180 | | - | |
| 172 | + | |
181 | 173 | | |
182 | 174 | | |
183 | | - | |
| 175 | + | |
184 | 176 | | |
185 | 177 | | |
186 | 178 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
0 commit comments