Paul Sajna 7 years ago
parent
commit
95e74373fe
3 changed files with 14 additions and 4 deletions
  1. 7 1
      platform/src/linux/mod.rs
  2. 6 2
      platform/src/redox/mod.rs
  3. 1 1
      src/unistd/src/lib.rs

+ 7 - 1
platform/src/linux/mod.rs

@@ -14,7 +14,7 @@ pub fn chdir(path: *const c_char) -> c_int {
     }
 }
 
-pub fn chown(path: *const c_char, owner: usize, group: usize) -> c_int {
+pub fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int {
     unsafe {
         syscall!(CHOWN, owner as u32, group as u32) as c_int
     }
@@ -45,6 +45,12 @@ pub fn exit(status: c_int) -> ! {
     loop {}
 }
 
+pub fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int {
+    unsafe {
+        syscall!(FCHOWN, owner, group) as c_int
+    }
+}
+
 #[cfg(target_arch = "x86_64")]
 pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
     unsafe {

+ 6 - 2
platform/src/redox/mod.rs

@@ -14,9 +14,9 @@ pub fn chdir(path: *const c_char) -> c_int {
     syscall::chdir(cstr_to_slice(path))? as c_int
 }
 
-pub fn chown(path: *const c_char, owner: usize, group: usize) -> c_int {
+pub fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int {
     let fd = syscall::open(cstr_to_slice(path));
-    syscall::fchown(fd, owner as u32, group as u32)? as c_int
+    syscall::fchown(fd, owner, group)? as c_int
 
 pub fn close(fd: c_int) -> c_int {
     syscall::close(fd as usize);
@@ -36,6 +36,10 @@ pub fn exit(status: c_int) -> ! {
     loop {}
 }
 
+pub fn fchown(fd: c_int, owner: uid_t, group: gid_t) -> c_int {
+    syscall::fchown(owner, group)? 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

@@ -131,7 +131,7 @@ pub extern "C" fn execvp(file: *const c_char, argv: *const *mut c_char) -> c_int
 
 #[no_mangle]
 pub extern "C" fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int {
-    unimplemented!();
+    platform::fchown(fildes, owner, group)
 }
 
 #[no_mangle]