You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2017/07/11 01:39:12 UTC

[26/50] mesos git commit: Windows: Cleaned up `os::var()`.

Windows: Cleaned up `os::var()`.

Review: https://reviews.apache.org/r/60320/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/04054e08
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/04054e08
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/04054e08

Branch: refs/heads/master
Commit: 04054e08cd42cc7c18a93d9f9b405a0f1d162cca
Parents: 41debf9
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 09:11:27 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:35 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/windows/os.hpp | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/04054e08/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/os.hpp b/3rdparty/stout/include/stout/windows/os.hpp
index 397ea0a..42fda71 100644
--- a/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/stout/include/stout/windows/os.hpp
@@ -21,7 +21,6 @@
 
 #include <sys/utime.h>
 
-#include <codecvt>
 #include <list>
 #include <map>
 #include <memory>
@@ -33,6 +32,7 @@
 #include <stout/nothing.hpp>
 #include <stout/option.hpp>
 #include <stout/path.hpp>
+#include <stout/stringify.hpp>
 #include <stout/strings.hpp>
 #include <stout/try.hpp>
 #include <stout/version.hpp>
@@ -805,19 +805,16 @@ inline Try<std::string> var()
     // The expected behavior here is for the function to "fail"
     // and return `false`, and `size` receives necessary buffer size.
     return WindowsError(
-        "os::var: `GetAllUsersProfileDirectory` succeeded unexpectedly");
+        "os::var: `GetAllUsersProfileDirectoryW` succeeded unexpectedly");
   }
 
-  std::vector<wchar_t> var_folder(size);
-  if (!::GetAllUsersProfileDirectoryW(&var_folder[0], &size)) {
-    return WindowsError(
-        "os::var: `GetAllUsersProfileDirectory` failed");
+  std::vector<wchar_t> buffer;
+  buffer.reserve(static_cast<size_t>(size));
+  if (!::GetAllUsersProfileDirectoryW(buffer.data(), &size)) {
+    return WindowsError("os::var: `GetAllUsersProfileDirectoryW` failed");
   }
 
-  // Convert UTF-16 `wchar[]` to UTF-8 `string`.
-  std::wstring wvar_folder(&var_folder[0]);
-  std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> converter;
-  return converter.to_bytes(wvar_folder);
+  return stringify(std::wstring(buffer.data()));
 }