2011-06-15 13:19:50 -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-09-01 19:27:58 -05:00
|
|
|
fn open(s: str::sbuf, flags: int, mode: uint) -> int;
|
2011-07-27 07:19:39 -05:00
|
|
|
fn close(fd: int) -> int;
|
2010-09-22 17:44:13 -05:00
|
|
|
type FILE;
|
2011-09-01 19:27:58 -05:00
|
|
|
fn fopen(path: str::sbuf, mode: str::sbuf) -> FILE;
|
|
|
|
fn fdopen(fd: int, mode: str::sbuf) -> FILE;
|
2011-07-27 07:19:39 -05:00
|
|
|
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;
|
2010-09-22 17:44:13 -05:00
|
|
|
type dir;
|
2011-09-01 19:27:58 -05:00
|
|
|
fn opendir(d: str::sbuf) -> dir;
|
2011-07-27 07:19:39 -05:00
|
|
|
fn closedir(d: dir) -> int;
|
2011-03-10 08:56:51 -06:00
|
|
|
type dirent;
|
2011-07-27 07:19:39 -05:00
|
|
|
fn readdir(d: dir) -> dirent;
|
2011-09-01 19:27:58 -05:00
|
|
|
fn getenv(n: str::sbuf) -> str::sbuf;
|
|
|
|
fn setenv(n: str::sbuf, v: str::sbuf, overwrite: int) -> int;
|
|
|
|
fn unsetenv(n: str::sbuf) -> int;
|
2011-07-27 07:19:39 -05:00
|
|
|
fn pipe(buf: *mutable int) -> int;
|
|
|
|
fn waitpid(pid: int, status: &mutable int, options: 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; }
|
|
|
|
fn O_APPEND() -> int { ret 8; }
|
|
|
|
fn O_CREAT() -> int { ret 512; }
|
|
|
|
fn O_EXCL() -> int { ret 2048; }
|
|
|
|
fn O_TRUNC() -> int { ret 1024; }
|
|
|
|
fn O_TEXT() -> int {
|
|
|
|
ret 0; // nonexistent in darwin libc
|
2010-09-22 17:44:13 -05:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
}
|
|
|
|
fn O_BINARY() -> int {
|
|
|
|
ret 0; // nonexistent in darwin libc
|
2010-09-22 17:44:13 -05:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
}
|
|
|
|
fn S_IRUSR() -> uint { ret 1024u; }
|
|
|
|
fn S_IWUSR() -> uint { ret 512u; }
|
2010-10-22 13:46:33 -05:00
|
|
|
}
|
|
|
|
|
2011-09-02 17:34:58 -05:00
|
|
|
fn exec_suffix() -> str { ret ""; }
|
2010-10-22 18:15:06 -05:00
|
|
|
|
2011-09-02 17:34:58 -05:00
|
|
|
fn target_os() -> str { ret "macos"; }
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-09-02 17:34:58 -05:00
|
|
|
fn dylib_filename(base: &str) -> str { ret "lib" + base + ".dylib"; }
|
2011-03-15 18:56:59 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn pipe() -> {in: int, out: int} {
|
|
|
|
let fds = {mutable in: 0, mutable out: 0};
|
2011-07-26 07:06:02 -05:00
|
|
|
assert (os::libc::pipe(ptr::addr_of(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-08-31 19:34:50 -05:00
|
|
|
fn fd_FILE(fd: int) -> libc::FILE {
|
2011-09-02 17:34:58 -05:00
|
|
|
ret str::as_buf("r", {|modebuf| libc::fdopen(fd, modebuf) });
|
2011-08-31 19:34:50 -05:00
|
|
|
}
|
2011-03-11 06:30:18 -06:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
fn waitpid(pid: int) -> int {
|
|
|
|
let status = 0;
|
2011-07-12 19:50:56 -05:00
|
|
|
assert (os::libc::waitpid(pid, status, 0) != -1);
|
|
|
|
ret status;
|
2011-03-11 06:30:18 -06:00
|
|
|
}
|
2011-06-17 13:12:51 -05:00
|
|
|
|
|
|
|
native "rust" mod rustrt {
|
2011-09-02 17:34:58 -05:00
|
|
|
fn rust_getcwd() -> str;
|
2011-06-17 13:12:51 -05:00
|
|
|
}
|
|
|
|
|
2011-09-02 17:34:58 -05:00
|
|
|
fn getcwd() -> str { ret 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:
|