diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-08-27 21:01:27 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-08-27 21:01:27 +0200 |
| commit | 286ae72fb7954ee51a6f4a1aeacbed6be4e6f37e (patch) | |
| tree | 45e20a1f23787b05c5fb549dd9b051d05979ff9f /src/libstd/sys/unix/os.rs | |
| parent | 11946956a6352f49c6aadc1c13c39757a046e0c2 (diff) | |
| download | rust-286ae72fb7954ee51a6f4a1aeacbed6be4e6f37e.tar.gz rust-286ae72fb7954ee51a6f4a1aeacbed6be4e6f37e.zip | |
Clean code a bit
Diffstat (limited to 'src/libstd/sys/unix/os.rs')
| -rw-r--r-- | src/libstd/sys/unix/os.rs | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index e61804efd50..82606d2c728 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -584,18 +584,15 @@ pub fn home_dir() -> Option<PathBuf> { n if n < 0 => 512 as usize, n => n as usize, }; - let me = libc::getuid(); - loop { - let mut buf = Vec::with_capacity(amt); - let mut passwd: libc::passwd = mem::zeroed(); - - if getpwduid_r(me, &mut passwd, &mut buf).is_some() { - let ptr = passwd.pw_dir as *const _; - let bytes = CStr::from_ptr(ptr).to_bytes().to_vec(); - return Some(OsStringExt::from_vec(bytes)) - } else { - return None; - } + 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 } } } |
