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/macos_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/macos_os.rs')
| -rw-r--r-- | src/lib/macos_os.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/macos_os.rs b/src/lib/macos_os.rs index bacf2d8a..a484f72b 100644 --- a/src/lib/macos_os.rs +++ b/src/lib/macos_os.rs @@ -9,6 +9,7 @@ native mod libc = "libc.dylib" { 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); @@ -24,6 +25,9 @@ native mod libc = "libc.dylib" { 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 { @@ -49,6 +53,22 @@ fn target_os() -> str { ret "macos"; } +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; |