Paul Sajna пре 7 година
родитељ
комит
9de89e037a
3 измењених фајлова са 12 додато и 1 уклоњено
  1. 6 0
      platform/src/linux/mod.rs
  2. 5 0
      platform/src/redox/mod.rs
  3. 1 1
      src/unistd/src/lib.rs

+ 6 - 0
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 {

+ 5 - 0
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

+ 1 - 1
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]