MCPcopy Create free account
hub / github.com/HailToDodongo/pyrite64 / wslToWindowsPath

Function wslToWindowsPath

src/utils/proc.cpp:42–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40 }
41
42 std::optional<std::string> wslToWindowsPath(const std::string &path)
43 {
44 std::error_code absEc;
45 std::string linuxPath = fs::absolute(fs::path(path), absEc).generic_string();
46 if (absEc) linuxPath = fs::path(path).generic_string();
47
48 std::string escapedPath;
49 escapedPath.reserve(linuxPath.size());
50 for (char c : linuxPath) {
51 if (c == '\\' || c == '"') escapedPath.push_back('\\');
52 escapedPath.push_back(c);
53 }
54
55 std::string command = "wslpath -w -- \"" + escapedPath + "\"";
56 FILE* pipe = popen(command.c_str(), "r");
57 if (!pipe) return std::nullopt;
58
59 std::array<char, 256> buffer{};
60 std::string output;
61 while (fgets(buffer.data(), static_cast<int>(buffer.size()), pipe) != nullptr) {
62 output += buffer.data();
63 }
64
65 if (pclose(pipe) != 0) return std::nullopt;
66
67 while (!output.empty() && (output.back() == '\n' || output.back() == '\r')) {
68 output.pop_back();
69 }
70
71 return output.empty() ? std::nullopt : std::optional<std::string>{output};
72 }
73#endif
74}
75

Callers 2

openFileMethod · 0.85
openInFileBrowserMethod · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected