Skip to content

Commit 5789539

Browse files
simplify home_dir by removing unnecessary getpwuid_r wrapper
1 parent ebf70a9 commit 5789539

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

src/libstd/sys/unix/os.rs

+9-18
Original file line numberDiff line numberDiff line change
@@ -483,30 +483,21 @@ pub fn home_dir() -> Option<PathBuf> {
483483
target_os = "nacl",
484484
target_os = "emscripten")))]
485485
unsafe fn fallback() -> Option<OsString> {
486-
unsafe fn getpwduid_r(me: libc::uid_t, passwd: &mut libc::passwd,
487-
buf: &mut Vec<c_char>) -> Option<()> {
488-
let mut result = ptr::null_mut();
489-
match libc::getpwuid_r(me, passwd, buf.as_mut_ptr(),
490-
buf.capacity(),
491-
&mut result) {
492-
0 if !result.is_null() => Some(()),
493-
_ => None
494-
}
495-
}
496-
497486
let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) {
498487
n if n < 0 => 512 as usize,
499488
n => n as usize,
500489
};
501490
let mut buf = Vec::with_capacity(amt);
502491
let mut passwd: libc::passwd = mem::zeroed();
503-
504-
if getpwduid_r(libc::getuid(), &mut passwd, &mut buf).is_some() {
505-
let ptr = passwd.pw_dir as *const _;
506-
let bytes = CStr::from_ptr(ptr).to_bytes().to_vec();
507-
Some(OsStringExt::from_vec(bytes))
508-
} else {
509-
None
492+
let mut result = ptr::null_mut();
493+
match libc::getpwuid_r(libc::getuid(), &mut passwd, buf.as_mut_ptr(),
494+
buf.capacity(), &mut result) {
495+
0 if !result.is_null() => {
496+
let ptr = passwd.pw_dir as *const _;
497+
let bytes = CStr::from_ptr(ptr).to_bytes().to_vec();
498+
Some(OsStringExt::from_vec(bytes))
499+
},
500+
_ => None,
510501
}
511502
}
512503
}

0 commit comments

Comments
 (0)