| 1792 | |
| 1793 | #ifdef _WIN32 |
| 1794 | Result<NativePathString> GetEnvVarNative(std::string_view name) { |
| 1795 | ARROW_ASSIGN_OR_RAISE(std::wstring w_name, StringToNative(name)); |
| 1796 | std::wstring value(100, '\0'); |
| 1797 | |
| 1798 | uint32_t res = GetEnvironmentVariableW(w_name.data(), value.data(), |
| 1799 | static_cast<uint32_t>(value.size())); |
| 1800 | if (res >= value.size()) { |
| 1801 | // Value buffer too small, need to upsize |
| 1802 | // (`res` includes the null-terminating character in this case) |
| 1803 | value.resize(res); |
| 1804 | res = GetEnvironmentVariableW(w_name.data(), value.data(), |
| 1805 | static_cast<uint32_t>(value.size())); |
| 1806 | } |
| 1807 | if (res == 0) { |
| 1808 | return Status::KeyError("environment variable '", name, "' undefined"); |
| 1809 | } |
| 1810 | // On success, `res` does not include the null-terminating character |
| 1811 | DCHECK_EQ(value.data()[res], 0); |
| 1812 | value.resize(res); |
| 1813 | return value; |
| 1814 | } |
| 1815 | |
| 1816 | #else |
| 1817 |
no test coverage detected