Auto merge of #36048 - GuillaumeGomez:code_clean, r=brson
Clean code a bit
This commit is contained in:
commit
c615b21533
1 changed files with 8 additions and 11 deletions
|
@ -584,18 +584,15 @@ pub fn home_dir() -> Option<PathBuf> {
|
||||||
n if n < 0 => 512 as usize,
|
n if n < 0 => 512 as usize,
|
||||||
n => n as usize,
|
n => n as usize,
|
||||||
};
|
};
|
||||||
let me = libc::getuid();
|
let mut buf = Vec::with_capacity(amt);
|
||||||
loop {
|
let mut passwd: libc::passwd = mem::zeroed();
|
||||||
let mut buf = Vec::with_capacity(amt);
|
|
||||||
let mut passwd: libc::passwd = mem::zeroed();
|
|
||||||
|
|
||||||
if getpwduid_r(me, &mut passwd, &mut buf).is_some() {
|
if getpwduid_r(libc::getuid(), &mut passwd, &mut buf).is_some() {
|
||||||
let ptr = passwd.pw_dir as *const _;
|
let ptr = passwd.pw_dir as *const _;
|
||||||
let bytes = CStr::from_ptr(ptr).to_bytes().to_vec();
|
let bytes = CStr::from_ptr(ptr).to_bytes().to_vec();
|
||||||
return Some(OsStringExt::from_vec(bytes))
|
Some(OsStringExt::from_vec(bytes))
|
||||||
} else {
|
} else {
|
||||||
return None;
|
None
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue