Skip to content

Commit

Permalink
Rollup merge of rust-lang#84712 - joshtriplett:simplify-chdir, r=yaahc
Browse files Browse the repository at this point in the history
Simplify chdir implementation and minimize unsafe block
  • Loading branch information
Dylan-DPC committed May 5, 2021
2 parents da482cc + 8a2e67e commit ab9c15e
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions library/std/src/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit ab9c15e

Please sign in to comment.