rust/src/lib/win32_os.rs

88 lines
2.6 KiB
Rust
Raw Normal View History

import str::sbuf;
import vec::vbuf;
2010-06-24 06:03:09 +02:00
native "cdecl" mod libc = "" {
2011-07-27 14:19:39 +02:00
fn open(s: sbuf, flags: int, mode: uint) -> int = "_open";
fn read(fd: int, buf: vbuf, count: uint) -> int = "_read";
fn write(fd: int, buf: vbuf, count: uint) -> int = "_write";
fn close(fd: int) -> int = "_close";
type FILE;
2011-07-27 14:19:39 +02: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 fread(buf: vbuf, size: uint, n: uint, f: FILE) -> uint;
fn fwrite(buf: vbuf, size: uint, n: uint, f: FILE) -> uint;
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-24 06:03:09 +02:00
}
native "cdecl" mod libc_ivec = "" {
2011-07-27 14:19:39 +02: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;
}
mod libc_constants {
fn O_RDONLY() -> int { ret 0; }
fn O_WRONLY() -> int { ret 1; }
fn O_RDWR() -> int { ret 2; }
2011-07-27 14:19:39 +02: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; }
fn S_IRUSR() -> uint {
ret 256u; // really _S_IREAD in win32
}
fn S_IWUSR() -> uint {
ret 128u; // really _S_IWRITE in win32
}
2010-10-22 20:46:33 +02:00
}
2011-07-18 02:11:40 +02:00
native "x86stdcall" mod kernel32 {
2011-07-27 14:19:39 +02:00
fn GetEnvironmentVariableA(n: sbuf, v: sbuf, nsize: uint) -> uint;
fn SetEnvironmentVariableA(n: sbuf, v: sbuf) -> int;
2011-07-18 02:11:40 +02:00
}
fn exec_suffix() -> str { ret ".exe"; }
fn target_os() -> str { ret "win32"; }
2011-07-27 14:19:39 +02:00
fn dylib_filename(base: str) -> str { ret base + ".dll"; }
2011-07-27 14:19:39 +02:00
fn pipe() -> {in: int, out: int} {
let fds = {mutable in: 0, mutable out: 0};
assert (os::libc::_pipe(ptr::addr_of(fds.in), 1024u,
libc_constants::O_BINARY()) == 0);
2011-07-27 14:19:39 +02:00
ret {in: fds.in, out: fds.out};
}
2011-07-27 14:19:39 +02:00
fn fd_FILE(fd: int) -> libc::FILE { ret libc::_fdopen(fd, str::buf("r")); }
native "rust" mod rustrt {
2011-07-27 14:19:39 +02:00
fn rust_process_wait(handle: int) -> int;
fn rust_getcwd() -> str;
}
2011-07-27 14:19:39 +02:00
fn waitpid(pid: int) -> int { ret rustrt::rust_process_wait(pid); }
fn getcwd() -> str { ret rustrt::rust_getcwd(); }
// Local Variables:
// mode: rust;
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End: