diff --git a/platform/src/linux/mod.rs b/platform/src/linux/mod.rs index 20c1d59355..e810f8d483 100644 --- a/platform/src/linux/mod.rs +++ b/platform/src/linux/mod.rs @@ -51,6 +51,12 @@ pub fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int { } } +pub fn fchdir(fildes: c_int) -> c_int { + unsafe { + syscall!(FCHDIR, fildes) as c_int + } +} + #[cfg(target_arch = "x86_64")] pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int { unsafe { diff --git a/platform/src/redox/mod.rs b/platform/src/redox/mod.rs index 02755a3c9e..f80e5fd3de 100644 --- a/platform/src/redox/mod.rs +++ b/platform/src/redox/mod.rs @@ -40,6 +40,11 @@ pub fn fchown(fd: c_int, owner: uid_t, group: gid_t) -> c_int { syscall::fchown(owner, group)? as c_int } +pub fn fchdir(fd: c_int) -> c_int { + let path = fpath(fd as usize, &[]).unwrap(); + syscall::chdir(path)? as c_int +} + pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int { let path = unsafe { c_str(path) }; syscall::open(path, (oflag as usize) | (mode as usize)).unwrap() as c_int diff --git a/src/unistd/src/lib.rs b/src/unistd/src/lib.rs index 2b7de078b4..d60f11bcee 100644 --- a/src/unistd/src/lib.rs +++ b/src/unistd/src/lib.rs @@ -136,7 +136,7 @@ pub extern "C" fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int { #[no_mangle] pub extern "C" fn fchdir(fildes: c_int) -> c_int { - unimplemented!(); + platform::fchdir(fildes) } #[no_mangle]