adb: Use a default _SC_GETPW_R_SIZE_MAX size
sysconf(_SC_GETPW_R_SIZE_MAX) may return −1 if there is no hard limit on the the buffer size. Some libc implementations such as musl don't define this limit and will return -1. Use a default buffer size to handle this case. Change-Id: I997b13a2c2dca00574e049a259135e61c8ed8e03 Signed-off-by: Robert Yang <decatf@gmail.com>
This commit is contained in:
parent
ac305c82d6
commit
88c997d4eb
1 changed files with 3 additions and 0 deletions
|
@ -293,6 +293,9 @@ std::string adb_get_homedir_path() {
|
|||
struct passwd pwent;
|
||||
struct passwd* result;
|
||||
int pwent_max = sysconf(_SC_GETPW_R_SIZE_MAX);
|
||||
if (pwent_max == -1) {
|
||||
pwent_max = 16384;
|
||||
}
|
||||
std::vector<char> buf(pwent_max);
|
||||
int rc = getpwuid_r(getuid(), &pwent, buf.data(), buf.size(), &result);
|
||||
if (rc == 0 && result) {
|
||||
|
|
Loading…
Reference in a new issue