diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2021-05-06 13:30:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-06 13:30:55 +0200 |
| commit | 2ed0134cfa15205b9dace10649b4c550c84a7eba (patch) | |
| tree | 20e3e56d93b233ec13d3cd47644d7bea91fcc283 | |
| parent | 6a6c64401681471bb3223a2f4190ecd82a590cfa (diff) | |
| parent | 8a2e67e0d0826f73531f79ecc8d14aba71a8d837 (diff) | |
| download | rust-2ed0134cfa15205b9dace10649b4c550c84a7eba.tar.gz rust-2ed0134cfa15205b9dace10649b4c550c84a7eba.zip | |
Rollup merge of #84712 - joshtriplett:simplify-chdir, r=yaahc
Simplify chdir implementation and minimize unsafe block
| -rw-r--r-- | library/std/src/sys/unix/os.rs | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs index 984c08c2ad5..51c3e5d175c 100644 --- a/library/std/src/sys/unix/os.rs +++ b/library/std/src/sys/unix/os.rs @@ -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> { |
