diff --git a/src/platform/Cargo.toml b/src/platform/Cargo.toml index a00eb79be66d2e09c11a77b6723042ef6f334f30..e25b8251c0c6bb44761c2f5a8af2e7eda0c70881 100644 --- a/src/platform/Cargo.toml +++ b/src/platform/Cargo.toml @@ -8,6 +8,3 @@ sc = "0.2" [target.'cfg(target_os = "redox")'.dependencies] redox_syscall = "0.1" - -[dependencies] -alloc-no-stdlib = "1.2" diff --git a/src/platform/src/lib.rs b/src/platform/src/lib.rs index 6359118c7112f7ceb3e99f5d01f69a611adcc33c..5f57298db7e1faacb1908029f3449b491e7d674e 100644 --- a/src/platform/src/lib.rs +++ b/src/platform/src/lib.rs @@ -3,8 +3,6 @@ #![no_std] #![allow(non_camel_case_types)] //TODO #![feature(thread_local)] -#![feature(alloc)] -extern crate alloc; #[cfg(all(not(feature = "no_std"), target_os = "linux"))] #[macro_use] diff --git a/src/platform/src/redox/mod.rs b/src/platform/src/redox/mod.rs index e9fe6ddaff40ae61c7bd064cd1e820c6a8ee46fa..5a18ed234b5a9a525741b4a1131e90a848175da7 100644 --- a/src/platform/src/redox/mod.rs +++ b/src/platform/src/redox/mod.rs @@ -1,8 +1,5 @@ -extern crate alloc; - use core::ptr; use core::slice; -use alloc::Vec; use syscall; use c_str; @@ -127,11 +124,11 @@ pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int { } pub fn pipe(fds: [c_int; 2]) -> c_int { - let usize_vec = fds.iter().map(|x| *x as usize).collect::<Vec<usize>>(); - let usize_slice = usize_vec.as_slice(); - let mut usize_arr: [usize; 2] = Default::default(); - usize_arr.copy_from_slice(usize_slice); - e(syscall::pipe2(&mut usize_arr, 0)) as c_int + let mut usize_fds: [usize; 2] = [0; 2]; + let res = e(syscall::pipe2(&mut usize_fds)); + fds[0] = usize_fds[0] as c_int; + fds[1] = usize_fds[1] as c_int; + res as c_int } pub fn read(fd: c_int, buf: &mut [u8]) -> ssize_t { diff --git a/tests/pipe.c b/tests/pipe.c index 0ad78bc3e526891ee72e6e3c36a6a0e4deeef21d..6772cd5112701bd36613d505806daa86d5edd75f 100644 --- a/tests/pipe.c +++ b/tests/pipe.c @@ -1,4 +1,5 @@ //http://www2.cs.uregina.ca/~hamilton/courses/330/notes/unix/pipes/pipes.html +#include <string.h> #include <unistd.h> int main() @@ -6,18 +7,27 @@ int main() int pid, pip[2]; char instring[20]; + char * outstring = "Hello World!"; - pipe(pip); + pipe(pip); pid = fork(); if (pid == 0) /* child : sends message to parent*/ { + /* close read end */ + close(pip[0]); /* send 7 characters in the string, including end-of-string */ - write(pip[1], "Hi Mom!", 7); + write(pip[1], outstring, strlen(outstring)); + /* close write end */ + close(pip[1]); } else /* parent : receives message from child */ { + /* close write end */ + close(pip[1]); /* read from the pipe */ read(pip[0], instring, 7); + /* close read end */ + close(pip[0]); } }