2011-06-15 13:19:50 -05:00
|
|
|
|
2011-05-17 13:41:41 -05:00
|
|
|
import str::sbuf;
|
2010-06-23 23:03:09 -05:00
|
|
|
|
2011-06-28 07:21:13 -05:00
|
|
|
native "cdecl" mod libc = "" {
|
2011-08-12 12:40:25 -05:00
|
|
|
fn read(fd: int, buf: *u8, count: uint) -> int;
|
|
|
|
fn write(fd: int, buf: *u8, count: uint) -> int;
|
|
|
|
fn fread(buf: *u8, size: uint, n: uint, f: libc::FILE) -> uint;
|
|
|
|
fn fwrite(buf: *u8, size: uint, n: uint, f: libc::FILE) -> uint;
|
2011-07-27 07:19:39 -05:00
|
|
|
fn open(s: sbuf, flags: int, mode: uint) -> int = "_open";
|
|
|
|
fn close(fd: int) -> int = "_close";
|
2010-09-22 17:44:13 -05:00
|
|
|
type FILE;
|
2011-07-27 07:19:39 -05:00
|
|
|
fn fopen(path: sbuf, mode: sbuf) -> FILE;
|
|
|
|
fn _fdopen(fd: int, mode: sbuf) -> FILE;
|
|
|
|
fn fclose(f: FILE);
|
|
|
|
fn fgetc(f: FILE) -> int;
|
|
|
|
fn ungetc(c: int, f: FILE);
|
|
|
|
fn feof(f: FILE) -> int;
|
|
|
|
fn fseek(f: FILE, offset: int, whence: int) -> int;
|
|
|
|
fn ftell(f: FILE) -> int;
|
|
|
|
fn _pipe(fds: *mutable int, size: uint, mode: int) -> int;
|
2010-06-23 23:03:09 -05:00
|
|
|
}
|
2010-08-04 19:14:11 -05:00
|
|
|
|
|
|
|
mod libc_constants {
|
2011-06-15 13:19:50 -05:00
|
|
|
fn O_RDONLY() -> int { ret 0; }
|
|
|
|
fn O_WRONLY() -> int { ret 1; }
|
|
|
|
fn O_RDWR() -> int { ret 2; }
|
2011-07-27 07:19:39 -05:00
|
|
|
fn O_APPEND() -> int { ret 8; }
|
|
|
|
fn O_CREAT() -> int { ret 256; }
|
|
|
|
fn O_EXCL() -> int { ret 1024; }
|
|
|
|
fn O_TRUNC() -> int { ret 512; }
|
|
|
|
fn O_TEXT() -> int { ret 16384; }
|
|
|
|
fn O_BINARY() -> int { ret 32768; }
|
2011-08-19 17:16:48 -05:00
|
|
|
fn O_NOINHERIT() -> int { ret 128; }
|
2011-06-15 13:19:50 -05:00
|
|
|
fn S_IRUSR() -> uint {
|
|
|
|
ret 256u; // really _S_IREAD in win32
|
2010-08-04 19:14:11 -05:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
}
|
|
|
|
fn S_IWUSR() -> uint {
|
|
|
|
ret 128u; // really _S_IWRITE in win32
|
2010-09-22 17:44:13 -05:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
}
|
2010-10-22 13:46:33 -05:00
|
|
|
}
|
|
|
|
|
2011-07-17 19:11:40 -05:00
|
|
|
native "x86stdcall" mod kernel32 {
|
2011-07-27 07:19:39 -05:00
|
|
|
fn GetEnvironmentVariableA(n: sbuf, v: sbuf, nsize: uint) -> uint;
|
|
|
|
fn SetEnvironmentVariableA(n: sbuf, v: sbuf) -> int;
|
2011-07-17 19:11:40 -05:00
|
|
|
}
|
|
|
|
|
2011-08-25 13:11:21 -05:00
|
|
|
fn exec_suffix() -> istr { ret ~".exe"; }
|
2010-10-22 18:15:06 -05:00
|
|
|
|
2011-08-25 13:11:21 -05:00
|
|
|
fn target_os() -> istr { ret ~"win32"; }
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-08-25 13:11:21 -05:00
|
|
|
fn dylib_filename(base: &istr) -> istr { ret base + ~".dll"; }
|
2011-03-15 18:56:59 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn pipe() -> {in: int, out: int} {
|
2011-08-03 16:50:51 -05:00
|
|
|
// 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.
|
2011-07-27 07:19:39 -05:00
|
|
|
let fds = {mutable in: 0, mutable out: 0};
|
2011-08-19 17:16:48 -05:00
|
|
|
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);
|
2011-07-27 07:19:39 -05:00
|
|
|
ret {in: fds.in, out: fds.out};
|
2011-03-11 06:30:18 -06:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn fd_FILE(fd: int) -> libc::FILE { ret libc::_fdopen(fd, str::buf("r")); }
|
2011-03-11 06:30:18 -06:00
|
|
|
|
|
|
|
native "rust" mod rustrt {
|
2011-07-27 07:19:39 -05:00
|
|
|
fn rust_process_wait(handle: int) -> int;
|
2011-06-17 13:12:51 -05:00
|
|
|
fn rust_getcwd() -> str;
|
2011-03-11 06:30:18 -06:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn waitpid(pid: int) -> int { ret rustrt::rust_process_wait(pid); }
|
2011-06-17 13:12:51 -05:00
|
|
|
|
2011-08-25 13:11:21 -05:00
|
|
|
fn getcwd() -> istr {
|
|
|
|
ret istr::from_estr(rustrt::rust_getcwd());
|
|
|
|
}
|
2011-06-17 13:12:51 -05:00
|
|
|
|
2010-09-22 17:44:13 -05:00
|
|
|
// Local Variables:
|
|
|
|
// mode: rust;
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
2011-06-15 14:01:19 -05:00
|
|
|
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
2010-09-22 17:44:13 -05:00
|
|
|
// End:
|