2011-06-15 13:19:50 -05:00
|
|
|
|
2011-05-17 13:41:41 -05:00
|
|
|
import str::sbuf;
|
|
|
|
import vec::vbuf;
|
2010-06-23 23:03:09 -05:00
|
|
|
|
2011-06-28 07:21:13 -05:00
|
|
|
native "cdecl" mod libc = "" {
|
2011-06-15 13:39:31 -05:00
|
|
|
fn open(sbuf s, int flags, uint mode) -> int = "_open";
|
|
|
|
fn read(int fd, vbuf buf, uint count) -> int = "_read";
|
|
|
|
fn write(int fd, vbuf buf, uint count) -> int = "_write";
|
|
|
|
fn close(int fd) -> int = "_close";
|
2010-09-22 17:44:13 -05:00
|
|
|
type FILE;
|
|
|
|
fn fopen(sbuf path, sbuf mode) -> FILE;
|
2011-03-11 06:30:18 -06:00
|
|
|
fn _fdopen(int fd, sbuf mode) -> FILE;
|
2010-09-22 17:44:13 -05:00
|
|
|
fn fclose(FILE f);
|
|
|
|
fn fgetc(FILE f) -> int;
|
|
|
|
fn ungetc(int c, FILE f);
|
2011-03-25 15:54:54 -05:00
|
|
|
fn feof(FILE f) -> int;
|
2011-03-10 09:02:53 -06:00
|
|
|
fn fread(vbuf buf, uint size, uint n, FILE f) -> uint;
|
2011-03-22 18:38:47 -05:00
|
|
|
fn fwrite(vbuf buf, uint size, uint n, FILE f) -> uint;
|
2011-03-10 09:02:53 -06:00
|
|
|
fn fseek(FILE f, int offset, int whence) -> int;
|
2011-03-21 18:40:26 -05:00
|
|
|
fn ftell(FILE f) -> int;
|
2011-07-12 19:50:56 -05:00
|
|
|
fn _pipe(*mutable int fds, uint size, int mode) -> int;
|
2010-06-23 23:03:09 -05:00
|
|
|
}
|
2010-08-04 19:14:11 -05:00
|
|
|
|
2011-07-10 14:47:51 -05:00
|
|
|
native "cdecl" mod libc_ivec = "" {
|
|
|
|
fn read(int fd, *u8 buf, uint count) -> int;
|
|
|
|
fn write(int fd, *u8 buf, uint count) -> int;
|
|
|
|
fn fread(*u8 buf, uint size, uint n, libc::FILE f) -> uint;
|
|
|
|
fn fwrite(*u8 buf, uint size, uint n, libc::FILE f) -> uint;
|
|
|
|
}
|
|
|
|
|
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-21 20:10:11 -05:00
|
|
|
fn O_APPEND() -> int { ret 0x0008; }
|
|
|
|
fn O_CREAT() -> int { ret 0x0100; }
|
|
|
|
fn O_EXCL() -> int { ret 0x0400; }
|
|
|
|
fn O_TRUNC() -> int { ret 0x0200; }
|
|
|
|
fn O_TEXT() -> int { ret 0x4000; }
|
|
|
|
fn O_BINARY() -> int { ret 0x8000; }
|
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 {
|
|
|
|
fn GetEnvironmentVariableA(sbuf n, sbuf v, uint nsize) -> uint;
|
|
|
|
fn SetEnvironmentVariableA(sbuf n, sbuf v) -> int;
|
|
|
|
}
|
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
fn exec_suffix() -> str { ret ".exe"; }
|
2010-10-22 18:15:06 -05:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
fn target_os() -> str { ret "win32"; }
|
|
|
|
|
|
|
|
fn dylib_filename(str base) -> str { ret base + ".dll"; }
|
2011-03-15 18:56:59 -05:00
|
|
|
|
2011-07-26 07:06:02 -05:00
|
|
|
fn pipe() -> rec(int in, int out) {
|
|
|
|
auto fds = rec(mutable int=0, mutable out=0);
|
|
|
|
assert (os::libc::_pipe(ptr::addr_of(fds.in), 1024u,
|
2011-07-13 04:36:09 -05:00
|
|
|
libc_constants::O_BINARY()) == 0);
|
2011-07-26 07:06:02 -05:00
|
|
|
ret rec(in=fds.in, out=fds.out);
|
2011-03-11 06:30:18 -06:00
|
|
|
}
|
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
fn fd_FILE(int fd) -> libc::FILE { ret libc::_fdopen(fd, str::buf("r")); }
|
2011-03-11 06:30:18 -06:00
|
|
|
|
|
|
|
native "rust" mod rustrt {
|
|
|
|
fn rust_process_wait(int handle) -> int;
|
2011-06-17 13:12:51 -05:00
|
|
|
fn rust_getcwd() -> str;
|
2011-03-11 06:30:18 -06:00
|
|
|
}
|
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
fn waitpid(int pid) -> int { ret rustrt::rust_process_wait(pid); }
|
2011-06-17 13:12:51 -05:00
|
|
|
|
|
|
|
fn getcwd() -> str { ret rustrt::rust_getcwd(); }
|
|
|
|
|
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:
|