diff options
| author | Marijn Haverbeke <[email protected]> | 2011-03-11 13:30:18 +0100 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2011-03-14 14:57:13 -0700 |
| commit | ea5dc54c3f0444fd3f20191fa1b1d94372c74c65 (patch) | |
| tree | 0a80b98563553f56962cc956e94210462a9d66e2 /src/lib/linux_os.rs | |
| parent | Extend stream functionality (diff) | |
| download | rust-ea5dc54c3f0444fd3f20191fa1b1d94372c74c65.tar.xz rust-ea5dc54c3f0444fd3f20191fa1b1d94372c74c65.zip | |
Add functionality for running external programs to the std lib
See lib/run_program.rs.
Diffstat (limited to 'src/lib/linux_os.rs')
| -rw-r--r-- | src/lib/linux_os.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/lib/linux_os.rs b/src/lib/linux_os.rs index bed8fdbc..6695377d 100644 --- a/src/lib/linux_os.rs +++ b/src/lib/linux_os.rs @@ -1,6 +1,9 @@ import _str.sbuf; import _vec.vbuf; +// FIXE Somehow merge stuff duplicated here and macosx_os.rs. Made difficult +// by https://github.com/graydon/rust/issues#issue/268 + native mod libc = "libc.so.6" { fn open(sbuf s, int flags, uint mode) -> int; @@ -10,6 +13,7 @@ native mod libc = "libc.so.6" { type FILE; fn fopen(sbuf path, sbuf mode) -> FILE; + fn fdopen(int fd, sbuf mode) -> FILE; fn fclose(FILE f); fn fgetc(FILE f) -> int; fn ungetc(int c, FILE f); @@ -25,6 +29,9 @@ native mod libc = "libc.so.6" { 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; } mod libc_constants { @@ -50,6 +57,22 @@ fn target_os() -> str { ret "linux"; } +fn pipe() -> tup(int, int) { + let vec[mutable int] fds = vec(mutable 0, 0); + check(os.libc.pipe(_vec.buf[mutable int](fds)) == 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 = vec(mutable 0); + check(os.libc.waitpid(pid, _vec.buf[mutable int](status), 0) != -1); + ret status.(0); +} + // Local Variables: // mode: rust; // fill-column: 78; |