9999#include " arrow/util/io_util.h"
100100#include " arrow/util/logging_internal.h"
101101#include " arrow/util/mutex.h"
102+ #include " arrow/util/value_parsing.h"
102103
103104// For filename conversion
104105#if defined(_WIN32)
@@ -1762,19 +1763,20 @@ Result<std::string> GetEnvVar(std::string_view name) {
17621763#ifdef _WIN32
17631764 // On Windows, getenv() reads an early copy of the process' environment
17641765 // which doesn't get updated when SetEnvironmentVariable() is called.
1765- constexpr int32_t bufsize = 2000 ;
1766- char c_str[bufsize];
1767- auto res = GetEnvironmentVariableA (name.data (), c_str, bufsize);
1768- if (res >= bufsize) {
1766+ constexpr int32_t kBufsize = 2000 ;
1767+ char c_str[kBufsize ];
1768+
1769+ auto res = GetEnvironmentVariableA (name.data (), c_str, kBufsize );
1770+ if (res >= kBufsize ) {
17691771 return Status::CapacityError (" environment variable value too long" );
17701772 } else if (res == 0 ) {
1771- return Status::KeyError (" environment variable '" , name, " 'undefined" );
1773+ return Status::KeyError (" environment variable '" , name, " ' undefined" );
17721774 }
17731775 return std::string (c_str);
17741776#else
17751777 char * c_str = getenv (name.data ());
17761778 if (c_str == nullptr ) {
1777- return Status::KeyError (" environment variable '" , name, " 'undefined" );
1779+ return Status::KeyError (" environment variable '" , name, " ' undefined" );
17781780 }
17791781 return std::string (c_str);
17801782#endif
@@ -1783,15 +1785,15 @@ Result<std::string> GetEnvVar(std::string_view name) {
17831785#ifdef _WIN32
17841786Result<NativePathString> GetEnvVarNative (std::string_view name) {
17851787 NativePathString w_name;
1786- constexpr int32_t bufsize = 2000 ;
1787- wchar_t w_str[bufsize ];
1788+ constexpr int32_t kBufsize = 2000 ;
1789+ wchar_t w_str[kBufsize ];
17881790
17891791 ARROW_ASSIGN_OR_RAISE (w_name, StringToNative (name));
1790- auto res = GetEnvironmentVariableW (w_name.c_str (), w_str, bufsize );
1791- if (res >= bufsize ) {
1792+ auto res = GetEnvironmentVariableW (w_name.c_str (), w_str, kBufsize );
1793+ if (res >= kBufsize ) {
17921794 return Status::CapacityError (" environment variable value too long" );
17931795 } else if (res == 0 ) {
1794- return Status::KeyError (" environment variable '" , name, " 'undefined" );
1796+ return Status::KeyError (" environment variable '" , name, " ' undefined" );
17951797 }
17961798 return NativePathString (w_str);
17971799}
@@ -1804,6 +1806,18 @@ Result<NativePathString> GetEnvVarNative(std::string_view name) {
18041806
18051807#endif
18061808
1809+ Result<int64_t > GetEnvVarInteger (std::string_view name, std::optional<int64_t > min_value,
1810+ std::optional<int64_t > max_value) {
1811+ ARROW_ASSIGN_OR_RAISE (auto env_string, GetEnvVar (name));
1812+ int64_t value;
1813+ if (!ParseValue<Int64Type>(env_string.data (), env_string.length (), &value) ||
1814+ (min_value.has_value () && value < *min_value) ||
1815+ (max_value.has_value () && value > *max_value)) {
1816+ return Status::Invalid (" Invalid value for " , name, " : '" , env_string, " '" );
1817+ }
1818+ return value;
1819+ }
1820+
18071821Status SetEnvVar (std::string_view name, std::string_view value) {
18081822#ifdef _WIN32
18091823 if (SetEnvironmentVariableA (name.data (), value.data ())) {
0 commit comments