diff options
| author | Shawn Walker-Salas <shawn.walker@oracle.com> | 2017-02-15 22:52:47 -0800 |
|---|---|---|
| committer | Shawn Walker-Salas <shawn.walker@oracle.com> | 2017-02-15 22:52:47 -0800 |
| commit | 57895393115c61ec01fcbc9815f9821b2bfe5886 (patch) | |
| tree | 967ad44bb112ccb89ea42bb946c37b639e6490a6 /src/libstd/sys/unix/os.rs | |
| parent | ebf70a9a206e3ecff7d442a7edf297731e9fe042 (diff) | |
| download | rust-57895393115c61ec01fcbc9815f9821b2bfe5886.tar.gz rust-57895393115c61ec01fcbc9815f9821b2bfe5886.zip | |
simplify home_dir by removing unnecessary getpwuid_r wrapper
Diffstat (limited to 'src/libstd/sys/unix/os.rs')
| -rw-r--r-- | src/libstd/sys/unix/os.rs | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 1dbfa640d52..e78928c2667 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -483,30 +483,21 @@ pub fn home_dir() -> Option<PathBuf> { target_os = "nacl", target_os = "emscripten")))] unsafe fn fallback() -> Option<OsString> { - unsafe fn getpwduid_r(me: libc::uid_t, passwd: &mut libc::passwd, - buf: &mut Vec<c_char>) -> Option<()> { - let mut result = ptr::null_mut(); - match libc::getpwuid_r(me, passwd, buf.as_mut_ptr(), - buf.capacity(), - &mut result) { - 0 if !result.is_null() => Some(()), - _ => None - } - } - let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) { n if n < 0 => 512 as usize, n => n as usize, }; let mut buf = Vec::with_capacity(amt); let mut passwd: libc::passwd = mem::zeroed(); - - if getpwduid_r(libc::getuid(), &mut passwd, &mut buf).is_some() { - let ptr = passwd.pw_dir as *const _; - let bytes = CStr::from_ptr(ptr).to_bytes().to_vec(); - Some(OsStringExt::from_vec(bytes)) - } else { - None + let mut result = ptr::null_mut(); + match libc::getpwuid_r(libc::getuid(), &mut passwd, buf.as_mut_ptr(), + buf.capacity(), &mut result) { + 0 if !result.is_null() => { + let ptr = passwd.pw_dir as *const _; + let bytes = CStr::from_ptr(ptr).to_bytes().to_vec(); + Some(OsStringExt::from_vec(bytes)) + }, + _ => None, } } } |
