diff options
| author | Brian Anderson <banderson@mozilla.com> | 2011-08-03 14:50:51 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-08-03 15:09:00 -0700 |
| commit | 4ae6c835cb69332e982babcfca1a4e5657ec8bbd (patch) | |
| tree | 3c0a0618f8ff22673529bb412bdf72194d1407f0 /src/lib | |
| parent | e33de59e47c5076a89eadeb38f4934f58a3618a6 (diff) | |
| download | rust-4ae6c835cb69332e982babcfca1a4e5657ec8bbd.tar.gz rust-4ae6c835cb69332e982babcfca1a4e5657ec8bbd.zip | |
Add some hacks to get stdin piping working more correctly in windows
The way pipes work in windows is not the same as unix, though I'm not entirely clear on the differences. This patch changes the windows pipe method to return non-inheritable fds, and the windows rust_run_program method to duplicate them before spawning the new process. This allows make-check-pretty to work on windows.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/win32_os.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/lib/win32_os.rs b/src/lib/win32_os.rs index 65ee769fb5c..c502ebbfcb7 100644 --- a/src/lib/win32_os.rs +++ b/src/lib/win32_os.rs @@ -38,6 +38,7 @@ mod libc_constants { fn O_TRUNC() -> int { ret 512; } fn O_TEXT() -> int { ret 16384; } fn O_BINARY() -> int { ret 32768; } + fn O_NOINHERIT() -> int { ret 0x0080; } fn S_IRUSR() -> uint { ret 256u; // really _S_IREAD in win32 @@ -60,9 +61,18 @@ fn target_os() -> str { ret "win32"; } fn dylib_filename(base: str) -> str { ret base + ".dll"; } fn pipe() -> {in: int, out: int} { + // Windows pipes work subtly differently than unix pipes, and their + // inheritance has to be handled in a different way that I don't fully + // understand. Here we explicitly make the pipe non-inheritable, + // which means to pass it to a subprocess they need to be duplicated + // first, as in rust_run_program. let fds = {mutable in: 0, mutable out: 0}; - assert (os::libc::_pipe(ptr::addr_of(fds.in), 1024u, - libc_constants::O_BINARY()) == 0); + let res = os::libc::_pipe(ptr::addr_of(fds.in), 1024u, + libc_constants::O_BINARY() + | libc_constants::O_NOINHERIT()); + assert res == 0; + assert fds.in != -1 && fds.in != 0; + assert fds.out != -1 && fds.in != 0; ret {in: fds.in, out: fds.out}; } |
