Paul Sajna 7 ani în urmă
părinte
comite
151d873aba
6 a modificat fișierele cu 21 adăugiri și 1 ștergeri
  1. 6 0
      platform/src/linux/mod.rs
  2. 6 0
      platform/src/redox/mod.rs
  3. 1 1
      src/unistd/src/lib.rs
  4. 2 0
      tests/.gitignore
  5. 1 0
      tests/Makefile
  6. 5 0
      tests/link.c

+ 6 - 0
platform/src/linux/mod.rs

@@ -122,6 +122,12 @@ pub fn getuid() -> uid_t {
     }
 }
 
+pub fn link(path1: *const c_char, path2: *const c_char) -> c_int {
+    unsafe {
+        syscall!(LINK, path1, path2) 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 - 0
platform/src/redox/mod.rs

@@ -92,6 +92,12 @@ pub fn getuid() -> uid_t {
     syscall::getuid()? as pid_t
 }
 
+pub fn link(path1: const c_char, path2: const c_char) -> c_int {
+    let path1 = unsafe { c_str(path1) };
+    let path2 = unsafe { c_str(path2) };
+    syscall::link(path1, path2)? 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

@@ -261,7 +261,7 @@ pub extern "C" fn lchown(path: *const c_char, owner: uid_t, group: gid_t) -> c_i
 
 #[no_mangle]
 pub extern "C" fn link(path1: *const c_char, path2: *const c_char) -> c_int {
-    unimplemented!();
+    platform::link(path1, path2)
 }
 
 #[no_mangle]

+ 2 - 0
tests/.gitignore

@@ -11,6 +11,8 @@
 /ftruncate
 /ftruncate.out
 /getid
+/link
+/link.out
 /math
 /printf
 /write

+ 1 - 0
tests/Makefile

@@ -9,6 +9,7 @@ BINS=\
 	fsync \
 	ftruncate \
 	getid \
+	link \
 	math \
 	printf \
 	write

+ 5 - 0
tests/link.c

@@ -0,0 +1,5 @@
+#include <unistd.h>
+
+int main(int argc, char** argv) {
+    int status = link("link.c", "link.out");
+}