upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

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