stdlib: Make pipe and waitpid use interior vectors

This commit is contained in:
Patrick Walton 2011-07-12 17:50:56 -07:00
parent e53cfb979b
commit 13c44f99ae
3 changed files with 20 additions and 20 deletions

View File

@ -29,8 +29,8 @@ native "cdecl" mod libc = "" {
fn getenv(sbuf n) -> sbuf;
fn setenv(sbuf n, sbuf v, int overwrite) -> int;
fn unsetenv(sbuf n) -> int;
fn pipe(vbuf buf) -> int;
fn waitpid(int pid, vbuf status, int options) -> int;
fn pipe(*mutable int buf) -> int;
fn waitpid(int pid, &mutable int status, int options) -> int;
}
native "cdecl" mod libc_ivec = "" {
@ -67,16 +67,16 @@ fn target_os() -> str { ret "linux"; }
fn dylib_filename(str base) -> str { ret "lib" + base + ".so"; }
fn pipe() -> tup(int, int) {
let vec[mutable int] fds = [mutable 0, 0];
assert (os::libc::pipe(vec::buf(fds)) == 0);
ret tup(fds.(0), fds.(1));
auto fds = tup(mutable 0, 0);
assert (os::libc::pipe(ptr::addr_of(fds._0)) == 0);
ret tup(fds._0, fds._1);
}
fn fd_FILE(int fd) -> libc::FILE { ret libc::fdopen(fd, str::buf("r")); }
fn waitpid(int pid) -> int {
let vec[mutable int] status = [mutable 0];
assert (os::libc::waitpid(pid, vec::buf(status), 0) != -1);
auto status = 0;
assert (os::libc::waitpid(pid, status, 0) != -1);
ret status.(0);
}

View File

@ -26,8 +26,8 @@ native "cdecl" mod libc = "" {
fn getenv(sbuf n) -> sbuf;
fn setenv(sbuf n, sbuf v, int overwrite) -> int;
fn unsetenv(sbuf n) -> int;
fn pipe(vbuf buf) -> int;
fn waitpid(int pid, vbuf status, int options) -> int;
fn pipe(*mutable int buf) -> int;
fn waitpid(int pid, &mutable int status, int options) -> int;
}
native "cdecl" mod libc_ivec = "" {
@ -64,17 +64,17 @@ fn target_os() -> str { ret "macos"; }
fn dylib_filename(str base) -> str { ret "lib" + base + ".dylib"; }
fn pipe() -> tup(int, int) {
let vec[mutable int] fds = [mutable 0, 0];
assert (os::libc::pipe(vec::buf(fds)) == 0);
ret tup(fds.(0), fds.(1));
auto fds = tup(mutable 0, 0);
assert (os::libc::pipe(ptr::addr_of(fds._0)) == 0);
ret tup(fds._0, fds._1);
}
fn fd_FILE(int fd) -> libc::FILE { ret libc::fdopen(fd, str::buf("r")); }
fn waitpid(int pid) -> int {
let vec[mutable int] status = [mutable 0];
assert (os::libc::waitpid(pid, vec::buf(status), 0) != -1);
ret status.(0);
auto status = 0;
assert (os::libc::waitpid(pid, status, 0) != -1);
ret status;
}
native "rust" mod rustrt {

View File

@ -19,7 +19,7 @@ native "cdecl" mod libc = "" {
fn fseek(FILE f, int offset, int whence) -> int;
fn ftell(FILE f) -> int;
fn getenv(sbuf n) -> sbuf;
fn _pipe(vbuf fds, uint size, int mode) -> int;
fn _pipe(*mutable int fds, uint size, int mode) -> int;
}
native "cdecl" mod libc_ivec = "" {
@ -56,10 +56,10 @@ fn target_os() -> str { ret "win32"; }
fn dylib_filename(str base) -> str { ret base + ".dll"; }
fn pipe() -> tup(int, int) {
let vec[mutable int] fds = [mutable 0, 0];
assert (os::libc::_pipe(vec::buf(fds), 1024u, libc_constants::O_BINARY())
== 0);
ret tup(fds.(0), fds.(1));
auto fds = tup(mutable 0, 0);
assert (os::libc::pipe(ptr::addr_of(fds._0), 1024u,
libc_constants::O_BINARY()) == 0);
ret tup(fds._0, fds._1);
}
fn fd_FILE(int fd) -> libc::FILE { ret libc::_fdopen(fd, str::buf("r")); }