MCPcopy Create free account
hub / github.com/apache/arrow / GetEnvVar

Function GetEnvVar

cpp/src/arrow/util/io_util.cc:1762–1791  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1760//
1761
1762Result<std::string> GetEnvVar(std::string_view name) {
1763#ifdef _WIN32
1764 // On Windows, getenv() reads an early copy of the process' environment
1765 // which doesn't get updated when SetEnvironmentVariable() is called.
1766 std::string value(100, '\0');
1767
1768 uint32_t res = GetEnvironmentVariableA(name.data(), value.data(),
1769 static_cast<uint32_t>(value.size()));
1770 if (res >= value.size()) {
1771 // Value buffer too small, need to upsize
1772 // (`res` includes the null-terminating character in this case)
1773 value.resize(res);
1774 res = GetEnvironmentVariableA(name.data(), value.data(),
1775 static_cast<uint32_t>(value.size()));
1776 }
1777 if (res == 0) {
1778 return Status::KeyError("environment variable '", name, "' undefined");
1779 }
1780 // On success, `res` does not include the null-terminating character
1781 DCHECK_EQ(value.data()[res], 0);
1782 value.resize(res);
1783 return value;
1784#else
1785 char* c_str = getenv(name.data());
1786 if (c_str == nullptr) {
1787 return Status::KeyError("environment variable '", name, "' undefined");
1788 }
1789 return std::string(c_str);
1790#endif
1791}
1792
1793#ifdef _WIN32
1794Result<NativePathString> GetEnvVarNative(std::string_view name) {

Callers 15

UserSelectedBackendFunction · 0.85
IsDebugEnabledFunction · 0.85
MakeExporterFromEnvFunction · 0.85
SetUpMethod · 0.85
GetConnectionStringMethod · 0.85
CheckForRemoteTestMethod · 0.85
~FlightSqlDriverMethod · 0.85
RegisterLogMethod · 0.85
FromUriMethod · 0.85
DefaultsMethod · 0.85
EnvVarGuardMethod · 0.85

Calls 4

KeyErrorFunction · 0.85
resizeMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45

Tested by 4

SetUpMethod · 0.68
GetConnectionStringMethod · 0.68
CheckForRemoteTestMethod · 0.68
EnvVarGuardMethod · 0.68