Skip to content

Commit

Permalink
fix compilation issue on non-msvc systems
Browse files Browse the repository at this point in the history
  • Loading branch information
phlptp committed Jun 23, 2023
1 parent f5a19cd commit 5bde394
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions include/CLI/impl/StringTools_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,23 @@ CLI11_INLINE std::string &add_quotes_if_needed(std::string &str) {
return str;
}

std::string get_environment_value(const std::string &env_name) {
char *buffer = nullptr;
std::string get_environment_value(const std::string& env_name) {
char* buffer = nullptr;
std::string ename_string;

#ifdef _MSC_VER
// Windows version
std::size_t sz = 0;
if(_dupenv_s(&buffer, &sz, env_name.c_str()) == 0 && buffer != nullptr) {
if (_dupenv_s(&buffer, &sz, env_name.c_str()) == 0 && buffer != nullptr) {
ename_string = std::string(buffer);
free(buffer);
}
#else
// This also works on Windows, but gives a warning
buffer = std::getenv(opt->envname_.c_str());
if(buffer != nullptr)
buffer = std::getenv(env_name_.c_str());
if (buffer != nullptr) {
ename_string = std::string(buffer);
}
#endif
return ename_string;
}
Expand Down

0 comments on commit 5bde394

Please sign in to comment.