diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/cpp/BUILD | 3 | ||||
-rw-r--r-- | src/main/cpp/blaze_util_windows.cc | 22 |
2 files changed, 8 insertions, 17 deletions
diff --git a/src/main/cpp/BUILD b/src/main/cpp/BUILD index 82ed5510cf..e6bc52b085 100644 --- a/src/main/cpp/BUILD +++ b/src/main/cpp/BUILD @@ -48,7 +48,8 @@ cc_library( "//src:freebsd": [ ], "//src:windows_msvc": [ - "-Wl,ws2_32.lib", # for grpc + "-Wl,advapi32.lib", # GetUserNameW + "-Wl,ws2_32.lib", # grpc ], "//conditions:default": [ "-lrt", diff --git a/src/main/cpp/blaze_util_windows.cc b/src/main/cpp/blaze_util_windows.cc index 50afc7fb3d..d74bd8d9a2 100644 --- a/src/main/cpp/blaze_util_windows.cc +++ b/src/main/cpp/blaze_util_windows.cc @@ -18,7 +18,6 @@ #ifndef COMPILER_MSVC #include <fcntl.h> -#include <pwd.h> #include <sys/cygwin.h> #include <sys/ioctl.h> #include <sys/socket.h> @@ -28,6 +27,7 @@ #endif // COMPILER_MSVC #include <windows.h> +#include <lmcons.h> // UNLEN #include <cstdio> #include <cstdlib> @@ -1309,23 +1309,13 @@ void ReleaseLock(BlazeLock* blaze_lock) { #endif string GetUserName() { -#ifdef COMPILER_MSVC - // TODO(bazel-team): implement this. - pdie(255, "blaze::GetUserName is not implemented on Windows"); - return ""; -#else // not COMPILER_MSVC - string user = GetEnv("USER"); - if (!user.empty()) { - return user; - } - errno = 0; - passwd *pwent = getpwuid(getuid()); // NOLINT (single-threaded) - if (pwent == NULL || pwent->pw_name == NULL) { + WCHAR buffer[UNLEN + 1]; + DWORD len = UNLEN + 1; + if (!GetUserNameW(buffer, &len)) { pdie(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, - "$USER is not set, and unable to look up name of current user"); + "ERROR: GetUserNameW failed, err=%d\n", GetLastError()); } - return pwent->pw_name; -#endif // COMPILER_MSVC + return string(blaze_util::WstringToCstring(buffer).get()); } bool IsEmacsTerminal() { |