Rollup merge of #84712 - joshtriplett:simplify-chdir, r=yaahc

Simplify chdir implementation and minimize unsafe block
This commit is contained in:
Dylan DPC 2021-05-06 13:30:55 +02:00 committed by GitHub
commit 2ed0134cfa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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