You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mp...@apache.org on 2016/04/10 01:18:47 UTC
[4/8] mesos git commit: Stout: Implemented `os::setenv` on Windows.
Stout: Implemented `os::setenv` on Windows.
Review: https://reviews.apache.org/r/45888/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/fa72f742
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/fa72f742
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/fa72f742
Branch: refs/heads/master
Commit: fa72f74298a183c39cb53ddbfa65f038e27c6853
Parents: d5922af
Author: Alex Clemmer <cl...@gmail.com>
Authored: Sat Apr 9 15:55:40 2016 -0700
Committer: Michael Park <mp...@apache.org>
Committed: Sat Apr 9 15:58:35 2016 -0700
----------------------------------------------------------------------
.../3rdparty/stout/include/stout/windows/os.hpp | 25 ++++++++++++++++----
1 file changed, 20 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/fa72f742/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
index c48106e..e1a4557 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
@@ -45,17 +45,32 @@ inline int pagesize()
return si.dwPageSize;
}
-/*
+
// Sets the value associated with the specified key in the set of
// environment variables.
-inline void setenv(const std::string& key,
- const std::string& value,
- bool overwrite = true)
+inline void setenv(
+ const std::string& key,
+ const std::string& value,
+ bool overwrite = true)
{
- UNIMPLEMENTED;
+ // Do not set the variable if already set and `overwrite` was not specified.
+ //
+ // Per MSDN[1], `GetEnvironmentVariable` returns 0 on error and sets the
+ // error code to `ERROR_ENVVAR_NOT_FOUND` if the variable was not found.
+ //
+ // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms683188(v=vs.85).aspx
+ if (!overwrite &&
+ ::GetEnvironmentVariable(key.c_str(), NULL, 0) != 0 &&
+ ::GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
+ return;
+ }
+
+ // `SetEnvironmentVariable` returns an error code, but we can't act on it.
+ ::SetEnvironmentVariable(key.c_str(), value.c_str());
}
+/*
// Unsets the value associated with the specified key in the set of
// environment variables.
inline void unsetenv(const std::string& key)