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

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

@@ -69,6 +69,13 @@ pub fn ftruncate(fildes: c_int, length: off_t) -> c_int {
     }
 }
 
+pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char {
+    unsafe {
+        syscall!(GETCWD, buf, size);
+        buf as *mut c_char
+    }
+}
+
 #[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

@@ -55,6 +55,12 @@ pub fn ftruncate(fd: c_int, len: off_t) -> {
     syscall::ftruncate(fd as usize, len as usize)? as c_int
 }
 
+pub fn getcwd(buf: *mut c_char, size: size_t) -> {
+    // XXX: do something with size maybe
+    let rbuf = unsafe { c_str(buf) };
+    syscall::getcwd(rbuf)? 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

@@ -166,7 +166,7 @@ pub extern "C" fn ftruncate(fildes: c_int, length: off_t) -> c_int {
 
 #[no_mangle]
 pub extern "C" fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char {
-    unimplemented!();
+    platform::getcwd(buf, size)
 }
 
 #[no_mangle]