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 authored May 4, 2021
2 parents 0f0b7c7 + 8a2e67e commit a1a0e8c
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 a1a0e8c

Please sign in to comment.