| 106 | |
| 107 | #ifdef _WIN32 |
| 108 | static std::string wide_to_utf8(const wchar_t * ws) { |
| 109 | if (!ws || !*ws) { |
| 110 | return {}; |
| 111 | } |
| 112 | |
| 113 | const int len = static_cast<int>(std::wcslen(ws)); |
| 114 | const int bytes = WideCharToMultiByte(CP_UTF8, 0, ws, len, nullptr, 0, nullptr, nullptr); |
| 115 | if (bytes == 0) { |
| 116 | return {}; |
| 117 | } |
| 118 | |
| 119 | std::string utf8(bytes, '\0'); |
| 120 | WideCharToMultiByte(CP_UTF8, 0, ws, len, utf8.data(), bytes, nullptr, nullptr); |
| 121 | |
| 122 | return utf8; |
| 123 | } |
| 124 | #endif |
| 125 | |
| 126 | static std::vector<std::string> get_environment() { |