1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "remoting/host/username.h"
9 #include "base/logging.h"
13 #include <sys/types.h>
15 #endif // defined(OS_POSIX)
19 std::string
GetUsername() {
21 long buf_size
= sysconf(_SC_GETPW_R_SIZE_MAX
);
25 std::vector
<char> buf(buf_size
);
27 struct passwd
* passwd_result
= nullptr;
28 getpwuid_r(getuid(), &passwd
, &(buf
[0]), buf_size
, &passwd_result
);
29 return passwd_result
? passwd_result
->pw_name
: std::string();
30 #else // !defined(OS_POSIX)
33 #endif // defined(OS_POSIX)
36 } // namespace remoting