Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: remoting/host/username.cc

Issue 112353002: Move remoting::GetUsername() from remoting/base to remoting/host (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/username.h ('k') | remoting/remoting.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "remoting/host/username.h"
6
7 #include <vector>
8
9 #include "base/logging.h"
10
11 #if defined(OS_POSIX)
12 #include <pwd.h>
13 #include <sys/types.h>
14 #include <unistd.h>
15 #endif // defined(OS_POSIX)
16
17 namespace remoting {
18
19 std::string GetUsername() {
20 #if defined(OS_ANDROID)
rmsousa 2013/12/11 02:20:07 Can we remove this #ifdef ANDROID section? I susp
Sergey Ulanov 2013/12/11 02:22:50 Good point. Done
21 struct passwd* passwd = getpwuid(getuid());
22 return passwd ? passwd->pw_name : std::string();
23 #elif defined(OS_POSIX)
24 long buf_size = sysconf(_SC_GETPW_R_SIZE_MAX);
25 if (buf_size <= 0)
26 return std::string();
27
28 std::vector<char> buf(buf_size);
29 struct passwd passwd;
30 struct passwd* passwd_result = NULL;
31 getpwuid_r(getuid(), &passwd, &(buf[0]), buf_size, &passwd_result);
32 return passwd_result ? passwd_result->pw_name : std::string();
33 #else // !defined(OS_POSIX)
34 NOTIMPLEMENTED();
35 return std::string();
36 #endif // defined(OS_POSIX)
37 }
38
39 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/username.h ('k') | remoting/remoting.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698