summary refs log tree commit diff
path: root/library/std/src/sys
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2021-04-29 13:11:20 -0700
committerJosh Triplett <josh@joshtriplett.org>2021-04-29 13:11:20 -0700
commit8a2e67e0d0826f73531f79ecc8d14aba71a8d837 (patch)
tree00e12b9411affc098842da8ffc8b98fbe7005982 /library/std/src/sys
parent814a560072c305d274affc78219e4a7e0558252f (diff)
downloadrust-8a2e67e0d0826f73531f79ecc8d14aba71a8d837.tar.gz
rust-8a2e67e0d0826f73531f79ecc8d14aba71a8d837.zip
Simplify chdir implementation and minimize unsafe block
Diffstat (limited to 'library/std/src/sys')
-rw-r--r--library/std/src/sys/unix/os.rs8
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> {