Chromium Code Reviews| Index: remoting/base/util.cc |
| diff --git a/remoting/base/util.cc b/remoting/base/util.cc |
| index 58734229aa733d83c430291913bd389dc9564ddf..81d972ace2d176949de8ac078baae909344731b1 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,30 @@ bool StringIsUtf8(const char* data, size_t length) { |
| return true; |
| } |
| +bool CanGetUsername() { |
| +#if defined(OS_POSIX) |
| + return true; |
| +#else // !defined(OS_POSIX) |
| + return false; |
| +#endif // defined(OS_POSIX) |
| +} |
| + |
| +std::string GetUsername() { |
| +#if defined(OS_POSIX) |
| + long buf_size = sysconf(_SC_GETPW_R_SIZE_MAX); |
| + if (buf_size <= 0) |
| + return ""; |
|
Sergey Ulanov
2013/03/29 17:50:01
please use std::string() instead of ""
Lambros
2013/03/29 19:30:22
Done.
|
| + 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 ""; |
| + return std::string(passwd_result->pw_name); |
| +#else // !defined(OS_POSIX) |
| + NOTREACHED(); |
| + return ""; |
| +#endif // defined(OS_POSIX) |
| +} |
| + |
| } // namespace remoting |