Index: remoting/base/util.cc |
diff --git a/remoting/base/util.cc b/remoting/base/util.cc |
index 58734229aa733d83c430291913bd389dc9564ddf..53b121352954d103a343ea887626e2abce36d110 100644 |
--- a/remoting/base/util.cc |
+++ b/remoting/base/util.cc |
@@ -13,6 +13,12 @@ |
#include "media/base/yuv_convert.h" |
#include "third_party/skia/include/core/SkRegion.h" |
+#if defined(OS_POSIX) |
+#include <pwd.h> |
+#include <sys/types.h> |
+#include <unistd.h> |
+#endif // defined(OS_POSIX) |
+ |
using media::VideoFrame; |
namespace remoting { |
@@ -311,4 +317,21 @@ bool StringIsUtf8(const char* data, size_t length) { |
return true; |
} |
+std::string GetUsername() { |
+#if defined(OS_POSIX) |
+ long buf_size = sysconf(_SC_GETPW_R_SIZE_MAX); |
+ if (buf_size <= 0) |
+ return std::string(); |
+ scoped_array<char> buf(new char[buf_size]); |
+ struct passwd passwd; |
+ struct passwd* passwd_result = NULL; |
+ getpwuid_r(getuid(), &passwd, buf.get(), buf_size, &passwd_result); |
+ if (!passwd_result) |
+ return std::string(); |
+ return std::string(passwd_result->pw_name); |
+#else // !defined(OS_POSIX) |
+ return std::string(); |
+#endif // defined(OS_POSIX) |
+} |
+ |
} // namespace remoting |