Simplify chdir implementation and minimize unsafe block

This commit is contained in:
Josh Triplett 2021-04-29 13:11:20 -07:00
parent 814a560072
commit 8a2e67e0d0

View File

@ -155,12 +155,10 @@ pub fn getcwd() -> io::Result<PathBuf> {
pub fn chdir(p: &path::Path) -> io::Result<()> {
let p: &OsStr = p.as_ref();
let p = CString::new(p.as_bytes())?;
unsafe {
match libc::chdir(p.as_ptr()) == (0 as c_int) {
true => Ok(()),
false => Err(io::Error::last_os_error()),
}
if unsafe { libc::chdir(p.as_ptr()) } != 0 {
return Err(io::Error::last_os_error());
}
Ok(())
}
pub struct SplitPaths<'a> {