diff options
Diffstat (limited to 'runtime/shims/process.cpp')
| -rw-r--r-- | runtime/shims/process.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/runtime/shims/process.cpp b/runtime/shims/process.cpp index e21fb3028..14aac92c3 100644 --- a/runtime/shims/process.cpp +++ b/runtime/shims/process.cpp | |||
| @@ -44,17 +44,25 @@ HANDLE g_done = nullptr; | |||
| 44 | std::string quote(const std::string& a) { | 44 | std::string quote(const std::string& a) { |
| 45 | if (!a.empty() && a.find_first_of(" \t\"") == std::string::npos) return a; | 45 | if (!a.empty() && a.find_first_of(" \t\"") == std::string::npos) return a; |
| 46 | std::string out = "\""; | 46 | std::string out = "\""; |
| 47 | size_t slashes = 0; // CommandLineToArgvW: backslashes are literal unless they precede a quote | ||
| 47 | for (char c : a) { | 48 | for (char c : a) { |
| 48 | if (c == '"') out += '\\'; | 49 | if (c == '\\') { |
| 50 | ++slashes; | ||
| 51 | } else { | ||
| 52 | if (c == '"') out.append(slashes + 1, '\\'); | ||
| 53 | slashes = 0; | ||
| 54 | } | ||
| 49 | out += c; | 55 | out += c; |
| 50 | } | 56 | } |
| 51 | return out + "\""; | 57 | return out.append(slashes, '\\') + "\""; // a trailing run is doubled before the closing quote |
| 52 | } | 58 | } |
| 53 | 59 | ||
| 60 | // The narrow arguments are ANSI code page text (main.cpp passes std::filesystem::path::string(), and the CRT's | ||
| 61 | // narrow argv is ACP too); under a UTF-8 activeCodePage CP_ACP is UTF-8 anyway. | ||
| 54 | std::wstring widen(const std::string& s) { | 62 | std::wstring widen(const std::string& s) { |
| 55 | int n = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, nullptr, 0); | 63 | int n = MultiByteToWideChar(CP_ACP, 0, s.c_str(), -1, nullptr, 0); |
| 56 | std::wstring w(n > 0 ? n - 1 : 0, L'\0'); | 64 | std::wstring w(n > 0 ? n - 1 : 0, L'\0'); |
| 57 | if (n > 1) MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, w.data(), n); | 65 | if (n > 1) MultiByteToWideChar(CP_ACP, 0, s.c_str(), -1, w.data(), n); |
| 58 | return w; | 66 | return w; |
| 59 | } | 67 | } |
| 60 | 68 | ||