Skip to content

Commit 8a2e67e

Browse files
committed
Simplify chdir implementation and minimize unsafe block
1 parent 814a560 commit 8a2e67e

File tree

1 file changed

+3
-5
lines changed
  • library/std/src/sys/unix

1 file changed

+3
-5
lines changed

library/std/src/sys/unix/os.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,10 @@ pub fn getcwd() -> io::Result<PathBuf> {
155155
pub fn chdir(p: &path::Path) -> io::Result<()> {
156156
let p: &OsStr = p.as_ref();
157157
let p = CString::new(p.as_bytes())?;
158-
unsafe {
159-
match libc::chdir(p.as_ptr()) == (0 as c_int) {
160-
true => Ok(()),
161-
false => Err(io::Error::last_os_error()),
162-
}
158+
if unsafe { libc::chdir(p.as_ptr()) } != 0 {
159+
return Err(io::Error::last_os_error());
163160
}
161+
Ok(())
164162
}
165163

166164
pub struct SplitPaths<'a> {

0 commit comments

Comments
 (0)