Skip to content

Commit

Permalink
Simplify chdir implementation and minimize unsafe block
Browse files Browse the repository at this point in the history
  • Loading branch information
joshtriplett committed Apr 29, 2021
1 parent 814a560 commit 8a2e67e
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 8a2e67e

Please sign in to comment.