Skip to content

Commit

Permalink
Fix Windows and macOS clearenv implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Nov 1, 2023
1 parent 917faea commit 65f81d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions include/gz/utils/Environment.hh
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ bool GZ_UTILS_VISIBLE setenv(const EnvironmentMap &_vars);
/// concurrently with `setenv` or `unsetenv`
///
/// \return A string containing all environment variables
std::string printenv();

/// NOLINTNEXTLINE - This is incorrectly parsed as a global variable
std::string GZ_UTILS_VISIBLE printenv();
} // namespace GZ_UTILS_VERSION_NAMESPACE
} // namespace utils
} // namespace gz
Expand Down
14 changes: 10 additions & 4 deletions src/Environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,22 @@ bool unsetenv(const std::string &_name)
/////////////////////////////////////////////////
bool clearenv()
{
::clearenv();
return true;
/*
bool success = true;
#if __linux__
if (0 != ::clearenv())
{
success = false;

Check warning on line 111 in src/Environment.cc

View check run for this annotation

Codecov / codecov/patch

src/Environment.cc#L111

Added line #L111 was not covered by tests
}
#else
// Windows and macOS don't have clearenv
// so iterate and clear one-by-one
for (const auto &[key, value] : env())
{
success &= unsetenv(key);
}
#endif
return success;
*/

}

/////////////////////////////////////////////////
Expand Down

0 comments on commit 65f81d7

Please sign in to comment.