Update all modules to new Pal mechanism
This commit is contained in:
@@ -28,6 +28,9 @@ clean:
|
||||
cargo clean
|
||||
make -C tests clean
|
||||
|
||||
check:
|
||||
cargo check
|
||||
|
||||
fmt:
|
||||
./fmt.sh
|
||||
|
||||
|
||||
+4
-3
@@ -14,6 +14,7 @@ extern crate stdio;
|
||||
|
||||
use alloc::Vec;
|
||||
use core::ptr;
|
||||
use platform::{Pal, Sys};
|
||||
use platform::types::*;
|
||||
|
||||
#[no_mangle]
|
||||
@@ -95,7 +96,7 @@ pub unsafe extern "C" fn _start_rust(sp: &'static Stack) -> ! {
|
||||
stdio::stdout = stdio::default_stdout.get();
|
||||
stdio::stderr = stdio::default_stderr.get();
|
||||
|
||||
platform::exit(main(
|
||||
Sys::exit(main(
|
||||
argc,
|
||||
argv,
|
||||
// not envp, because programs like bash try to modify this *const*
|
||||
@@ -113,7 +114,7 @@ pub extern "C" fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! {
|
||||
let mut w = platform::FileWriter(2);
|
||||
let _ = w.write_fmt(format_args!("RELIBC CRT0 PANIC: {}\n", pi));
|
||||
|
||||
platform::exit(1);
|
||||
Sys::exit(1);
|
||||
}
|
||||
|
||||
#[lang = "oom"]
|
||||
@@ -129,5 +130,5 @@ pub extern "C" fn rust_oom(layout: ::core::alloc::Layout) -> ! {
|
||||
layout.align()
|
||||
));
|
||||
|
||||
platform::exit(1);
|
||||
Sys::exit(1);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ extern crate unistd;
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use core::{mem, ptr};
|
||||
use platform::{Pal, Sys};
|
||||
use platform::types::*;
|
||||
|
||||
const DIR_BUF_SIZE: usize = mem::size_of::<dirent>() * 3;
|
||||
@@ -41,7 +42,7 @@ pub struct dirent {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn opendir(path: *const c_char) -> *mut DIR {
|
||||
let fd = platform::open(
|
||||
let fd = Sys::open(
|
||||
path,
|
||||
fcntl::O_RDONLY | fcntl::O_DIRECTORY | fcntl::O_CLOEXEC,
|
||||
0,
|
||||
@@ -62,7 +63,7 @@ pub extern "C" fn opendir(path: *const c_char) -> *mut DIR {
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn closedir(dir: *mut DIR) -> c_int {
|
||||
let ret = platform::close((*dir).fd);
|
||||
let ret = Sys::close((*dir).fd);
|
||||
Box::from_raw(dir);
|
||||
ret
|
||||
}
|
||||
@@ -70,7 +71,7 @@ pub unsafe extern "C" fn closedir(dir: *mut DIR) -> c_int {
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn readdir(dir: *mut DIR) -> *mut dirent {
|
||||
if (*dir).index >= (*dir).len {
|
||||
let read = platform::getdents(
|
||||
let read = Sys::getdents(
|
||||
(*dir).fd,
|
||||
(*dir).buf.as_mut_ptr() as *mut platform::types::dirent,
|
||||
(*dir).buf.len(),
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
extern crate platform;
|
||||
|
||||
use platform::{Pal, Sys};
|
||||
use platform::types::*;
|
||||
|
||||
pub use sys::*;
|
||||
@@ -38,17 +39,10 @@ pub extern "C" fn creat(path: *const c_char, mode: mode_t) -> c_int {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn sys_fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int {
|
||||
platform::fcntl(fildes, cmd, arg)
|
||||
Sys::fcntl(fildes, cmd, arg)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn sys_open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
|
||||
platform::open(path, oflag, mode)
|
||||
Sys::open(path, oflag, mode)
|
||||
}
|
||||
|
||||
/*
|
||||
#[no_mangle]
|
||||
pub extern "C" fn func(args) -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
*/
|
||||
|
||||
+5
-3
@@ -43,6 +43,8 @@ pub extern crate utime;
|
||||
pub extern crate wchar;
|
||||
pub extern crate wctype;
|
||||
|
||||
use platform::{Pal, Sys};
|
||||
|
||||
#[cfg(not(test))]
|
||||
#[panic_implementation]
|
||||
#[linkage = "weak"]
|
||||
@@ -53,7 +55,7 @@ pub extern "C" fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! {
|
||||
let mut w = platform::FileWriter(2);
|
||||
let _ = w.write_fmt(format_args!("RELIBC PANIC: {}\n", pi));
|
||||
|
||||
platform::exit(1);
|
||||
Sys::exit(1);
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
@@ -76,7 +78,7 @@ pub extern "C" fn rust_oom(layout: ::core::alloc::Layout) -> ! {
|
||||
layout.align()
|
||||
));
|
||||
|
||||
platform::exit(1);
|
||||
Sys::exit(1);
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
@@ -89,5 +91,5 @@ pub extern "C" fn _Unwind_Resume() -> ! {
|
||||
let mut w = platform::FileWriter(2);
|
||||
let _ = w.write_str("_Unwind_Resume\n");
|
||||
|
||||
platform::exit(1);
|
||||
Sys::exit(1);
|
||||
}
|
||||
|
||||
@@ -26,11 +26,11 @@ mod allocator;
|
||||
#[path = "allocator/ralloc.rs"]
|
||||
mod allocator;
|
||||
|
||||
pub use pal::Pal;
|
||||
pub use pal::{Pal, PalSignal, PalSocket};
|
||||
|
||||
mod pal;
|
||||
|
||||
pub use sys::*;
|
||||
pub use sys::Sys;
|
||||
|
||||
#[cfg(all(not(feature = "no_std"), target_os = "linux"))]
|
||||
#[path = "linux/mod.rs"]
|
||||
@@ -149,7 +149,7 @@ pub struct FileWriter(pub c_int);
|
||||
|
||||
impl FileWriter {
|
||||
pub fn write(&mut self, buf: &[u8]) -> isize {
|
||||
write(self.0, buf)
|
||||
Sys::write(self.0, buf)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ pub struct FileReader(pub c_int);
|
||||
|
||||
impl FileReader {
|
||||
pub fn read(&mut self, buf: &mut [u8]) -> isize {
|
||||
read(self.0, buf)
|
||||
Sys::read(self.0, buf)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-146
@@ -1,10 +1,16 @@
|
||||
use core::{mem, ptr};
|
||||
use core::fmt::Write;
|
||||
|
||||
use FileWriter;
|
||||
use Pal;
|
||||
use errno;
|
||||
use types::*;
|
||||
|
||||
mod signal;
|
||||
mod socket;
|
||||
|
||||
const EINVAL: c_int = 22;
|
||||
const ENOSYS: c_int = 38;
|
||||
|
||||
const SIGCHLD: usize = 17;
|
||||
|
||||
@@ -31,18 +37,18 @@ fn e(sys: usize) -> usize {
|
||||
pub struct Sys;
|
||||
|
||||
impl Pal for Sys {
|
||||
unsafe fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int {
|
||||
e(syscall!(ACCEPT, socket, address, address_len)) as c_int
|
||||
fn no_pal(name: &str) -> c_int {
|
||||
let _ = writeln!(FileWriter(2), "relibc: no_pal: {}", name);
|
||||
unsafe {
|
||||
errno = ENOSYS;
|
||||
}
|
||||
-1
|
||||
}
|
||||
|
||||
fn access(path: *const c_char, mode: c_int) -> c_int {
|
||||
e(unsafe { syscall!(ACCESS, path, mode) }) as c_int
|
||||
}
|
||||
|
||||
unsafe fn bind(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int {
|
||||
e(syscall!(BIND, socket, address, address_len)) as c_int
|
||||
}
|
||||
|
||||
fn brk(addr: *mut c_void) -> *mut c_void {
|
||||
unsafe { syscall!(BRK, addr) as *mut c_void }
|
||||
}
|
||||
@@ -67,10 +73,6 @@ impl Pal for Sys {
|
||||
e(unsafe { syscall!(CLOSE, fildes) }) as c_int
|
||||
}
|
||||
|
||||
unsafe fn connect(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int {
|
||||
e(syscall!(CONNECT, socket, address, address_len)) as c_int
|
||||
}
|
||||
|
||||
fn dup(fildes: c_int) -> c_int {
|
||||
e(unsafe { syscall!(DUP, fildes) }) as c_int
|
||||
}
|
||||
@@ -168,7 +170,7 @@ impl Pal for Sys {
|
||||
let mut len = len;
|
||||
|
||||
let mut uts = mem::uninitialized();
|
||||
let err = uname(&mut uts);
|
||||
let err = Sys::uname(&mut uts);
|
||||
if err < 0 {
|
||||
mem::forget(uts);
|
||||
return err;
|
||||
@@ -195,14 +197,6 @@ impl Pal for Sys {
|
||||
e(unsafe { syscall!(GETITIMER, which, out) }) as c_int
|
||||
}
|
||||
|
||||
unsafe fn getpeername(
|
||||
socket: c_int,
|
||||
address: *mut sockaddr,
|
||||
address_len: *mut socklen_t,
|
||||
) -> c_int {
|
||||
e(syscall!(GETPEERNAME, socket, address, address_len)) as c_int
|
||||
}
|
||||
|
||||
fn getpgid(pid: pid_t) -> pid_t {
|
||||
e(unsafe { syscall!(GETPGID, pid) }) as pid_t
|
||||
}
|
||||
@@ -215,33 +209,6 @@ impl Pal for Sys {
|
||||
e(unsafe { syscall!(GETPPID) }) as pid_t
|
||||
}
|
||||
|
||||
unsafe fn getsockname(
|
||||
socket: c_int,
|
||||
address: *mut sockaddr,
|
||||
address_len: *mut socklen_t,
|
||||
) -> c_int {
|
||||
e(syscall!(GETSOCKNAME, socket, address, address_len)) as c_int
|
||||
}
|
||||
|
||||
fn getsockopt(
|
||||
socket: c_int,
|
||||
level: c_int,
|
||||
option_name: c_int,
|
||||
option_value: *mut c_void,
|
||||
option_len: *mut socklen_t,
|
||||
) -> c_int {
|
||||
e(unsafe {
|
||||
syscall!(
|
||||
GETSOCKOPT,
|
||||
socket,
|
||||
level,
|
||||
option_name,
|
||||
option_value,
|
||||
option_len
|
||||
)
|
||||
}) as c_int
|
||||
}
|
||||
|
||||
fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int {
|
||||
e(unsafe { syscall!(GETTIMEOFDAY, tp, tzp) }) as c_int
|
||||
}
|
||||
@@ -260,22 +227,10 @@ impl Pal for Sys {
|
||||
(Self::ioctl(fd, TIOCGWINSZ, &mut winsize as *mut _ as *mut c_void) == 0) as c_int
|
||||
}
|
||||
|
||||
fn kill(pid: pid_t, sig: c_int) -> c_int {
|
||||
e(unsafe { syscall!(KILL, pid, sig) }) as c_int
|
||||
}
|
||||
|
||||
fn killpg(pgrp: pid_t, sig: c_int) -> c_int {
|
||||
e(unsafe { syscall!(KILL, -(pgrp as isize) as pid_t, sig) }) as c_int
|
||||
}
|
||||
|
||||
fn link(path1: *const c_char, path2: *const c_char) -> c_int {
|
||||
e(unsafe { syscall!(LINKAT, AT_FDCWD, path1, AT_FDCWD, path2, 0) }) as c_int
|
||||
}
|
||||
|
||||
fn listen(socket: c_int, backlog: c_int) -> c_int {
|
||||
e(unsafe { syscall!(LISTEN, socket, backlog) }) as c_int
|
||||
}
|
||||
|
||||
fn lseek(fildes: c_int, offset: off_t, whence: c_int) -> off_t {
|
||||
e(unsafe { syscall!(LSEEK, fildes, offset, whence) }) as off_t
|
||||
}
|
||||
@@ -319,40 +274,10 @@ impl Pal for Sys {
|
||||
e(unsafe { syscall!(PIPE2, fildes.as_mut_ptr(), 0) }) as c_int
|
||||
}
|
||||
|
||||
fn raise(sig: c_int) -> c_int {
|
||||
let tid = e(unsafe { syscall!(GETTID) }) as pid_t;
|
||||
let ret = if tid == !0 {
|
||||
-1
|
||||
} else {
|
||||
e(unsafe { syscall!(TKILL, tid, sig) }) as c_int
|
||||
};
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
fn read(fildes: c_int, buf: &mut [u8]) -> ssize_t {
|
||||
e(unsafe { syscall!(READ, fildes, buf.as_mut_ptr(), buf.len()) }) as ssize_t
|
||||
}
|
||||
|
||||
unsafe fn recvfrom(
|
||||
socket: c_int,
|
||||
buf: *mut c_void,
|
||||
len: size_t,
|
||||
flags: c_int,
|
||||
address: *mut sockaddr,
|
||||
address_len: *mut socklen_t,
|
||||
) -> ssize_t {
|
||||
e(syscall!(
|
||||
RECVFROM,
|
||||
socket,
|
||||
buf,
|
||||
len,
|
||||
flags,
|
||||
address,
|
||||
address_len
|
||||
)) as ssize_t
|
||||
}
|
||||
|
||||
fn rename(old: *const c_char, new: *const c_char) -> c_int {
|
||||
e(unsafe { syscall!(RENAMEAT, AT_FDCWD, old, AT_FDCWD, new) }) as c_int
|
||||
}
|
||||
@@ -371,19 +296,6 @@ impl Pal for Sys {
|
||||
e(unsafe { syscall!(SELECT, nfds, readfds, writefds, exceptfds, timeout) }) as c_int
|
||||
}
|
||||
|
||||
unsafe fn sendto(
|
||||
socket: c_int,
|
||||
buf: *const c_void,
|
||||
len: size_t,
|
||||
flags: c_int,
|
||||
dest_addr: *const sockaddr,
|
||||
dest_len: socklen_t,
|
||||
) -> ssize_t {
|
||||
e(syscall!(
|
||||
SENDTO, socket, buf, len, flags, dest_addr, dest_len
|
||||
)) as ssize_t
|
||||
}
|
||||
|
||||
fn setitimer(which: c_int, new: *const itimerval, old: *mut itimerval) -> c_int {
|
||||
e(unsafe { syscall!(SETITIMER, which, new, old) }) as c_int
|
||||
}
|
||||
@@ -400,55 +312,10 @@ impl Pal for Sys {
|
||||
e(unsafe { syscall!(SETREUID, ruid, euid) }) as c_int
|
||||
}
|
||||
|
||||
fn setsockopt(
|
||||
socket: c_int,
|
||||
level: c_int,
|
||||
option_name: c_int,
|
||||
option_value: *const c_void,
|
||||
option_len: socklen_t,
|
||||
) -> c_int {
|
||||
e(unsafe {
|
||||
syscall!(
|
||||
SETSOCKOPT,
|
||||
socket,
|
||||
level,
|
||||
option_name,
|
||||
option_value,
|
||||
option_len
|
||||
)
|
||||
}) as c_int
|
||||
}
|
||||
|
||||
fn shutdown(socket: c_int, how: c_int) -> c_int {
|
||||
e(unsafe { syscall!(SHUTDOWN, socket, how) }) as c_int
|
||||
}
|
||||
|
||||
unsafe fn sigaction(sig: c_int, act: *const sigaction, oact: *mut sigaction) -> c_int {
|
||||
e(syscall!(
|
||||
RT_SIGACTION,
|
||||
sig,
|
||||
act,
|
||||
oact,
|
||||
mem::size_of::<sigset_t>()
|
||||
)) as c_int
|
||||
}
|
||||
|
||||
fn sigprocmask(how: c_int, set: *const sigset_t, oset: *mut sigset_t) -> c_int {
|
||||
e(unsafe { syscall!(RT_SIGPROCMASK, how, set, oset, mem::size_of::<sigset_t>()) }) as c_int
|
||||
}
|
||||
|
||||
fn stat(file: *const c_char, buf: *mut stat) -> c_int {
|
||||
e(unsafe { syscall!(NEWFSTATAT, AT_FDCWD, file, buf, 0) }) as c_int
|
||||
}
|
||||
|
||||
fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int {
|
||||
e(unsafe { syscall!(SOCKET, domain, kind, protocol) }) as c_int
|
||||
}
|
||||
|
||||
fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *mut c_int) -> c_int {
|
||||
e(unsafe { syscall!(SOCKETPAIR, domain, kind, protocol, socket_vector) }) as c_int
|
||||
}
|
||||
|
||||
fn tcgetattr(fd: c_int, out: *mut termios) -> c_int {
|
||||
Self::ioctl(fd, TCGETS, out as *mut c_void)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
use core::mem;
|
||||
|
||||
use super::{e, Sys};
|
||||
use PalSignal;
|
||||
use types::*;
|
||||
|
||||
impl PalSignal for Sys {
|
||||
fn kill(pid: pid_t, sig: c_int) -> c_int {
|
||||
e(unsafe { syscall!(KILL, pid, sig) }) as c_int
|
||||
}
|
||||
|
||||
fn killpg(pgrp: pid_t, sig: c_int) -> c_int {
|
||||
e(unsafe { syscall!(KILL, -(pgrp as isize) as pid_t, sig) }) as c_int
|
||||
}
|
||||
|
||||
fn raise(sig: c_int) -> c_int {
|
||||
let tid = e(unsafe { syscall!(GETTID) }) as pid_t;
|
||||
let ret = if tid == !0 {
|
||||
-1
|
||||
} else {
|
||||
e(unsafe { syscall!(TKILL, tid, sig) }) as c_int
|
||||
};
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
unsafe fn sigaction(sig: c_int, act: *const sigaction, oact: *mut sigaction) -> c_int {
|
||||
e(syscall!(
|
||||
RT_SIGACTION,
|
||||
sig,
|
||||
act,
|
||||
oact,
|
||||
mem::size_of::<sigset_t>()
|
||||
)) as c_int
|
||||
}
|
||||
|
||||
fn sigprocmask(how: c_int, set: *const sigset_t, oset: *mut sigset_t) -> c_int {
|
||||
e(unsafe { syscall!(RT_SIGPROCMASK, how, set, oset, mem::size_of::<sigset_t>()) }) as c_int
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
use super::{e, Sys};
|
||||
use PalSocket;
|
||||
use types::*;
|
||||
|
||||
impl PalSocket for Sys {
|
||||
unsafe fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int {
|
||||
e(syscall!(ACCEPT, socket, address, address_len)) as c_int
|
||||
}
|
||||
|
||||
unsafe fn bind(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int {
|
||||
e(syscall!(BIND, socket, address, address_len)) as c_int
|
||||
}
|
||||
|
||||
unsafe fn connect(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int {
|
||||
e(syscall!(CONNECT, socket, address, address_len)) as c_int
|
||||
}
|
||||
|
||||
unsafe fn getpeername(
|
||||
socket: c_int,
|
||||
address: *mut sockaddr,
|
||||
address_len: *mut socklen_t,
|
||||
) -> c_int {
|
||||
e(syscall!(GETPEERNAME, socket, address, address_len)) as c_int
|
||||
}
|
||||
|
||||
unsafe fn getsockname(
|
||||
socket: c_int,
|
||||
address: *mut sockaddr,
|
||||
address_len: *mut socklen_t,
|
||||
) -> c_int {
|
||||
e(syscall!(GETSOCKNAME, socket, address, address_len)) as c_int
|
||||
}
|
||||
|
||||
fn getsockopt(
|
||||
socket: c_int,
|
||||
level: c_int,
|
||||
option_name: c_int,
|
||||
option_value: *mut c_void,
|
||||
option_len: *mut socklen_t,
|
||||
) -> c_int {
|
||||
e(unsafe {
|
||||
syscall!(
|
||||
GETSOCKOPT,
|
||||
socket,
|
||||
level,
|
||||
option_name,
|
||||
option_value,
|
||||
option_len
|
||||
)
|
||||
}) as c_int
|
||||
}
|
||||
|
||||
fn listen(socket: c_int, backlog: c_int) -> c_int {
|
||||
e(unsafe { syscall!(LISTEN, socket, backlog) }) as c_int
|
||||
}
|
||||
|
||||
unsafe fn recvfrom(
|
||||
socket: c_int,
|
||||
buf: *mut c_void,
|
||||
len: size_t,
|
||||
flags: c_int,
|
||||
address: *mut sockaddr,
|
||||
address_len: *mut socklen_t,
|
||||
) -> ssize_t {
|
||||
e(syscall!(
|
||||
RECVFROM,
|
||||
socket,
|
||||
buf,
|
||||
len,
|
||||
flags,
|
||||
address,
|
||||
address_len
|
||||
)) as ssize_t
|
||||
}
|
||||
|
||||
unsafe fn sendto(
|
||||
socket: c_int,
|
||||
buf: *const c_void,
|
||||
len: size_t,
|
||||
flags: c_int,
|
||||
dest_addr: *const sockaddr,
|
||||
dest_len: socklen_t,
|
||||
) -> ssize_t {
|
||||
e(syscall!(
|
||||
SENDTO, socket, buf, len, flags, dest_addr, dest_len
|
||||
)) as ssize_t
|
||||
}
|
||||
|
||||
fn setsockopt(
|
||||
socket: c_int,
|
||||
level: c_int,
|
||||
option_name: c_int,
|
||||
option_value: *const c_void,
|
||||
option_len: socklen_t,
|
||||
) -> c_int {
|
||||
e(unsafe {
|
||||
syscall!(
|
||||
SETSOCKOPT,
|
||||
socket,
|
||||
level,
|
||||
option_name,
|
||||
option_value,
|
||||
option_len
|
||||
)
|
||||
}) as c_int
|
||||
}
|
||||
|
||||
fn shutdown(socket: c_int, how: c_int) -> c_int {
|
||||
e(unsafe { syscall!(SHUTDOWN, socket, how) }) as c_int
|
||||
}
|
||||
|
||||
fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int {
|
||||
e(unsafe { syscall!(SOCKET, domain, kind, protocol) }) as c_int
|
||||
}
|
||||
|
||||
fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *mut c_int) -> c_int {
|
||||
e(unsafe { syscall!(SOCKETPAIR, domain, kind, protocol, socket_vector) }) as c_int
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,21 @@
|
||||
use core::ptr;
|
||||
|
||||
use types::*;
|
||||
|
||||
pub trait Pal {
|
||||
fn no_pal<T>(name: &str) -> T;
|
||||
pub use self::signal::PalSignal;
|
||||
mod signal;
|
||||
|
||||
unsafe fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int {
|
||||
Self::no_pal("accept")
|
||||
}
|
||||
pub use self::socket::PalSocket;
|
||||
mod socket;
|
||||
|
||||
pub trait Pal {
|
||||
fn no_pal(name: &str) -> c_int;
|
||||
|
||||
fn access(path: *const c_char, mode: c_int) -> c_int {
|
||||
Self::no_pal("access")
|
||||
}
|
||||
|
||||
unsafe fn bind(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int {
|
||||
Self::no_pal("bind")
|
||||
}
|
||||
|
||||
fn brk(addr: *mut c_void) -> *mut c_void {
|
||||
Self::no_pal("brk")
|
||||
}
|
||||
fn brk(addr: *mut c_void) -> *mut c_void;
|
||||
|
||||
fn chdir(path: *const c_char) -> c_int {
|
||||
Self::no_pal("chdir")
|
||||
@@ -39,10 +37,6 @@ pub trait Pal {
|
||||
Self::no_pal("close")
|
||||
}
|
||||
|
||||
unsafe fn connect(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int {
|
||||
Self::no_pal("connect")
|
||||
}
|
||||
|
||||
fn dup(fildes: c_int) -> c_int {
|
||||
Self::no_pal("dup")
|
||||
}
|
||||
@@ -102,7 +96,8 @@ pub trait Pal {
|
||||
}
|
||||
|
||||
fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char {
|
||||
Self::no_pal("getcwd")
|
||||
Self::no_pal("getcwd");
|
||||
ptr::null_mut()
|
||||
}
|
||||
|
||||
fn getdents(fd: c_int, dirents: *mut dirent, bytes: usize) -> c_int {
|
||||
@@ -133,10 +128,6 @@ pub trait Pal {
|
||||
Self::no_pal("getitimer")
|
||||
}
|
||||
|
||||
unsafe fn getpeername(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int {
|
||||
Self::no_pal("getpeername")
|
||||
}
|
||||
|
||||
fn getpgid(pid: pid_t) -> pid_t {
|
||||
Self::no_pal("getpgid")
|
||||
}
|
||||
@@ -149,20 +140,6 @@ pub trait Pal {
|
||||
Self::no_pal("getppid")
|
||||
}
|
||||
|
||||
unsafe fn getsockname(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int {
|
||||
Self::no_pal("getsockname")
|
||||
}
|
||||
|
||||
fn getsockopt(
|
||||
socket: c_int,
|
||||
level: c_int,
|
||||
option_name: c_int,
|
||||
option_value: *mut c_void,
|
||||
option_len: *mut socklen_t,
|
||||
) -> c_int {
|
||||
Self::no_pal("getsockopt")
|
||||
}
|
||||
|
||||
fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int {
|
||||
Self::no_pal("gettimeofday")
|
||||
}
|
||||
@@ -179,24 +156,12 @@ pub trait Pal {
|
||||
Self::no_pal("isatty")
|
||||
}
|
||||
|
||||
fn kill(pid: pid_t, sig: c_int) -> c_int {
|
||||
Self::no_pal("kill")
|
||||
}
|
||||
|
||||
fn killpg(pgrp: pid_t, sig: c_int) -> c_int {
|
||||
Self::no_pal("killpg")
|
||||
}
|
||||
|
||||
fn link(path1: *const c_char, path2: *const c_char) -> c_int {
|
||||
Self::no_pal("link")
|
||||
}
|
||||
|
||||
fn listen(socket: c_int, backlog: c_int) -> c_int {
|
||||
Self::no_pal("listen")
|
||||
}
|
||||
|
||||
fn lseek(fildes: c_int, offset: off_t, whence: c_int) -> off_t {
|
||||
Self::no_pal("lseek")
|
||||
Self::no_pal("lseek") as off_t
|
||||
}
|
||||
|
||||
fn lstat(file: *const c_char, buf: *mut stat) -> c_int {
|
||||
@@ -219,7 +184,7 @@ pub trait Pal {
|
||||
fildes: c_int,
|
||||
off: off_t,
|
||||
) -> *mut c_void {
|
||||
Self::no_pal("mmap")
|
||||
Self::no_pal("mmap") as *mut c_void
|
||||
}
|
||||
|
||||
unsafe fn munmap(addr: *mut c_void, len: usize) -> c_int {
|
||||
@@ -238,23 +203,8 @@ pub trait Pal {
|
||||
Self::no_pal("pipe")
|
||||
}
|
||||
|
||||
fn raise(sig: c_int) -> c_int {
|
||||
Self::no_pal("raise")
|
||||
}
|
||||
|
||||
fn read(fildes: c_int, buf: &mut [u8]) -> ssize_t {
|
||||
Self::no_pal("read")
|
||||
}
|
||||
|
||||
unsafe fn recvfrom(
|
||||
socket: c_int,
|
||||
buf: *mut c_void,
|
||||
len: size_t,
|
||||
flags: c_int,
|
||||
address: *mut sockaddr,
|
||||
address_len: *mut socklen_t,
|
||||
) -> ssize_t {
|
||||
Self::no_pal("recvfrom")
|
||||
Self::no_pal("read") as ssize_t
|
||||
}
|
||||
|
||||
fn rename(old: *const c_char, new: *const c_char) -> c_int {
|
||||
@@ -275,17 +225,6 @@ pub trait Pal {
|
||||
Self::no_pal("select")
|
||||
}
|
||||
|
||||
unsafe fn sendto(
|
||||
socket: c_int,
|
||||
buf: *const c_void,
|
||||
len: size_t,
|
||||
flags: c_int,
|
||||
dest_addr: *const sockaddr,
|
||||
dest_len: socklen_t,
|
||||
) -> ssize_t {
|
||||
Self::no_pal("sendto")
|
||||
}
|
||||
|
||||
fn setitimer(which: c_int, new: *const itimerval, old: *mut itimerval) -> c_int {
|
||||
Self::no_pal("setitimer")
|
||||
}
|
||||
@@ -302,40 +241,10 @@ pub trait Pal {
|
||||
Self::no_pal("setreuid")
|
||||
}
|
||||
|
||||
fn setsockopt(
|
||||
socket: c_int,
|
||||
level: c_int,
|
||||
option_name: c_int,
|
||||
option_value: *const c_void,
|
||||
option_len: socklen_t,
|
||||
) -> c_int {
|
||||
Self::no_pal("setsockopt")
|
||||
}
|
||||
|
||||
fn shutdown(socket: c_int, how: c_int) -> c_int {
|
||||
Self::no_pal("shutdown")
|
||||
}
|
||||
|
||||
unsafe fn sigaction(sig: c_int, act: *const sigaction, oact: *mut sigaction) -> c_int {
|
||||
Self::no_pal("sigaction")
|
||||
}
|
||||
|
||||
fn sigprocmask(how: c_int, set: *const sigset_t, oset: *mut sigset_t) -> c_int {
|
||||
Self::no_pal("sigprocmask")
|
||||
}
|
||||
|
||||
fn stat(file: *const c_char, buf: *mut stat) -> c_int {
|
||||
Self::no_pal("stat")
|
||||
}
|
||||
|
||||
fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int {
|
||||
Self::no_pal("socket")
|
||||
}
|
||||
|
||||
fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *mut c_int) -> c_int {
|
||||
Self::no_pal("socketpair")
|
||||
}
|
||||
|
||||
fn tcgetattr(fd: c_int, out: *mut termios) -> c_int {
|
||||
Self::no_pal("tcgetattr")
|
||||
}
|
||||
@@ -345,11 +254,12 @@ pub trait Pal {
|
||||
}
|
||||
|
||||
fn times(out: *mut tms) -> clock_t {
|
||||
Self::no_pal("times")
|
||||
Self::no_pal("times") as clock_t
|
||||
}
|
||||
|
||||
fn umask(mask: mode_t) -> mode_t {
|
||||
Self::no_pal("umask")
|
||||
Self::no_pal("umask");
|
||||
0
|
||||
}
|
||||
|
||||
fn uname(utsname: *mut utsname) -> c_int {
|
||||
@@ -365,6 +275,6 @@ pub trait Pal {
|
||||
}
|
||||
|
||||
fn write(fildes: c_int, buf: &[u8]) -> ssize_t {
|
||||
Self::no_pal("write")
|
||||
Self::no_pal("write") as ssize_t
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
use Pal;
|
||||
use types::*;
|
||||
|
||||
pub trait PalSignal: Pal {
|
||||
fn kill(pid: pid_t, sig: c_int) -> c_int {
|
||||
Self::no_pal("kill")
|
||||
}
|
||||
|
||||
fn killpg(pgrp: pid_t, sig: c_int) -> c_int {
|
||||
Self::no_pal("killpg")
|
||||
}
|
||||
|
||||
fn raise(sig: c_int) -> c_int {
|
||||
Self::no_pal("raise")
|
||||
}
|
||||
|
||||
unsafe fn sigaction(sig: c_int, act: *const sigaction, oact: *mut sigaction) -> c_int {
|
||||
Self::no_pal("sigaction")
|
||||
}
|
||||
|
||||
fn sigprocmask(how: c_int, set: *const sigset_t, oset: *mut sigset_t) -> c_int {
|
||||
Self::no_pal("sigprocmask")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
use Pal;
|
||||
use types::*;
|
||||
|
||||
pub trait PalSocket: Pal {
|
||||
unsafe fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int {
|
||||
Self::no_pal("accept")
|
||||
}
|
||||
|
||||
unsafe fn bind(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int {
|
||||
Self::no_pal("bind")
|
||||
}
|
||||
|
||||
unsafe fn connect(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int {
|
||||
Self::no_pal("connect")
|
||||
}
|
||||
|
||||
unsafe fn getpeername(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int {
|
||||
Self::no_pal("getpeername")
|
||||
}
|
||||
|
||||
unsafe fn getsockname(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int {
|
||||
Self::no_pal("getsockname")
|
||||
}
|
||||
|
||||
fn getsockopt(
|
||||
socket: c_int,
|
||||
level: c_int,
|
||||
option_name: c_int,
|
||||
option_value: *mut c_void,
|
||||
option_len: *mut socklen_t,
|
||||
) -> c_int {
|
||||
Self::no_pal("getsockopt")
|
||||
}
|
||||
|
||||
fn listen(socket: c_int, backlog: c_int) -> c_int {
|
||||
Self::no_pal("listen")
|
||||
}
|
||||
|
||||
unsafe fn recvfrom(
|
||||
socket: c_int,
|
||||
buf: *mut c_void,
|
||||
len: size_t,
|
||||
flags: c_int,
|
||||
address: *mut sockaddr,
|
||||
address_len: *mut socklen_t,
|
||||
) -> ssize_t {
|
||||
Self::no_pal("recvfrom") as ssize_t
|
||||
}
|
||||
|
||||
unsafe fn sendto(
|
||||
socket: c_int,
|
||||
buf: *const c_void,
|
||||
len: size_t,
|
||||
flags: c_int,
|
||||
dest_addr: *const sockaddr,
|
||||
dest_len: socklen_t,
|
||||
) -> ssize_t {
|
||||
Self::no_pal("sendto") as ssize_t
|
||||
}
|
||||
|
||||
fn setsockopt(
|
||||
socket: c_int,
|
||||
level: c_int,
|
||||
option_name: c_int,
|
||||
option_value: *const c_void,
|
||||
option_len: socklen_t,
|
||||
) -> c_int {
|
||||
Self::no_pal("setsockopt")
|
||||
}
|
||||
|
||||
fn shutdown(socket: c_int, how: c_int) -> c_int {
|
||||
Self::no_pal("shutdown")
|
||||
}
|
||||
|
||||
fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int {
|
||||
Self::no_pal("socket")
|
||||
}
|
||||
|
||||
fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *mut c_int) -> c_int {
|
||||
Self::no_pal("socketpair")
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,19 @@
|
||||
use super::{close, dup, open, types::*};
|
||||
use core::ops::Deref;
|
||||
|
||||
use {Pal, Sys, types::*};
|
||||
|
||||
pub struct RawFile(c_int);
|
||||
|
||||
impl RawFile {
|
||||
pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> Result<RawFile, ()> {
|
||||
match open(path, oflag, mode) {
|
||||
match Sys::open(path, oflag, mode) {
|
||||
-1 => Err(()),
|
||||
n => Ok(RawFile(n)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dup(&self) -> Result<RawFile, ()> {
|
||||
match dup(self.0) {
|
||||
match Sys::dup(self.0) {
|
||||
-1 => Err(()),
|
||||
n => Ok(RawFile(n)),
|
||||
}
|
||||
@@ -33,7 +34,7 @@ impl RawFile {
|
||||
|
||||
impl Drop for RawFile {
|
||||
fn drop(&mut self) {
|
||||
let _ = close(self.0);
|
||||
let _ = Sys::close(self.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -10,6 +10,7 @@ extern crate platform;
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use core::ptr;
|
||||
use platform::{Pal, Sys};
|
||||
use platform::types::*;
|
||||
use platform::RawFile;
|
||||
|
||||
@@ -90,7 +91,7 @@ where
|
||||
buf.set_len(capacity);
|
||||
}
|
||||
|
||||
let read = platform::read(*file, &mut buf[len..]);
|
||||
let read = Sys::read(*file, &mut buf[len..]);
|
||||
|
||||
unsafe {
|
||||
buf.set_len(len + read as usize);
|
||||
|
||||
@@ -17,6 +17,7 @@ pub mod sys;
|
||||
pub use sys::*;
|
||||
|
||||
use core::{mem, ptr};
|
||||
use platform::{PalSignal, Sys};
|
||||
use platform::types::*;
|
||||
|
||||
const SIG_ERR: usize = !0;
|
||||
@@ -45,17 +46,17 @@ pub type sigset_t = c_ulong;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn kill(pid: pid_t, sig: c_int) -> c_int {
|
||||
platform::kill(pid, sig)
|
||||
Sys::kill(pid, sig)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn killpg(pgrp: pid_t, sig: c_int) -> c_int {
|
||||
platform::killpg(pgrp, sig)
|
||||
Sys::killpg(pgrp, sig)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn raise(sig: c_int) -> c_int {
|
||||
platform::raise(sig)
|
||||
Sys::raise(sig)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -72,7 +73,7 @@ pub unsafe extern "C" fn sigaction(
|
||||
} else {
|
||||
ptr::null_mut()
|
||||
};
|
||||
platform::sigaction(sig, ptr, oact as *mut platform::types::sigaction)
|
||||
Sys::sigaction(sig, ptr, oact as *mut platform::types::sigaction)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -176,7 +177,7 @@ pub extern "C" fn sigpending(set: *mut sigset_t) -> c_int {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn sigprocmask(how: c_int, set: *const sigset_t, oset: *mut sigset_t) -> c_int {
|
||||
platform::sigprocmask(how, set, oset)
|
||||
Sys::sigprocmask(how, set, oset)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
|
||||
+17
-13
@@ -22,6 +22,7 @@ use core::{ptr, str};
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use errno::STR_ERROR;
|
||||
use platform::{Pal, Sys};
|
||||
use platform::types::*;
|
||||
use platform::{c_str, errno, Read, Write};
|
||||
use vl::VaList as va_list;
|
||||
@@ -110,6 +111,7 @@ impl FILE {
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn write(&mut self, to_write: &[u8]) -> usize {
|
||||
if let Some((wbase, wpos, _)) = self.write {
|
||||
let len = wpos - wbase;
|
||||
@@ -119,9 +121,9 @@ impl FILE {
|
||||
let mut rem = f_buf.len() + to_write.len();
|
||||
loop {
|
||||
let mut count = if f_filled {
|
||||
platform::write(self.fd, &f_buf[advance..])
|
||||
Sys::write(self.fd, &f_buf[advance..])
|
||||
} else {
|
||||
platform::write(self.fd, &f_buf[advance..]) + platform::write(self.fd, to_write)
|
||||
Sys::write(self.fd, &f_buf[advance..]) + Sys::write(self.fd, to_write)
|
||||
};
|
||||
if count == rem as isize {
|
||||
self.write = if self.buf.len() == 0 {
|
||||
@@ -152,13 +154,14 @@ impl FILE {
|
||||
// -- Tommoa (20/6/2018)
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
pub fn read(&mut self, buf: &mut [u8]) -> usize {
|
||||
let adj = if self.buf.len() > 0 { 0 } else { 1 };
|
||||
let mut file_buf = &mut self.buf[self.unget..];
|
||||
let count = if buf.len() <= 1 - adj {
|
||||
platform::read(self.fd, &mut file_buf)
|
||||
Sys::read(self.fd, &mut file_buf)
|
||||
} else {
|
||||
platform::read(self.fd, buf) + platform::read(self.fd, &mut file_buf)
|
||||
Sys::read(self.fd, buf) + Sys::read(self.fd, &mut file_buf)
|
||||
};
|
||||
if count <= 0 {
|
||||
self.flags |= if count == 0 {
|
||||
@@ -182,8 +185,9 @@ impl FILE {
|
||||
}
|
||||
buf.len()
|
||||
}
|
||||
|
||||
pub fn seek(&self, off: off_t, whence: c_int) -> off_t {
|
||||
platform::lseek(self.fd, off, whence)
|
||||
Sys::lseek(self.fd, off, whence)
|
||||
}
|
||||
|
||||
pub fn lock(&mut self) -> LockGuard {
|
||||
@@ -266,7 +270,7 @@ pub extern "C" fn cuserid(_s: *mut c_char) -> *mut c_char {
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fclose(stream: &mut FILE) -> c_int {
|
||||
flockfile(stream);
|
||||
let r = helpers::fflush_unlocked(stream) | platform::close(stream.fd);
|
||||
let r = helpers::fflush_unlocked(stream) | Sys::close(stream.fd);
|
||||
if stream.flags & constants::F_PERM == 0 {
|
||||
// Not one of stdin, stdout or stderr
|
||||
unsafe {
|
||||
@@ -444,7 +448,7 @@ pub extern "C" fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FI
|
||||
if let Some(f) = unsafe { helpers::_fdopen(fd, mode) } {
|
||||
f
|
||||
} else {
|
||||
platform::close(fd);
|
||||
Sys::close(fd);
|
||||
ptr::null_mut()
|
||||
}
|
||||
}
|
||||
@@ -555,7 +559,7 @@ pub extern "C" fn freopen(
|
||||
let new = unsafe { &mut *new }; // Should be safe, new is not null
|
||||
if new.fd == stream.fd {
|
||||
new.fd = -1;
|
||||
} else if platform::dup2(new.fd, stream.fd) < 0
|
||||
} else if Sys::dup2(new.fd, stream.fd) < 0
|
||||
|| fcntl::sys_fcntl(stream.fd, fcntl::F_SETFL, flags & fcntl::O_CLOEXEC) < 0
|
||||
{
|
||||
fclose(new);
|
||||
@@ -824,9 +828,9 @@ pub extern "C" fn putw(w: c_int, stream: &mut FILE) -> c_int {
|
||||
/// Delete file or directory `path`
|
||||
#[no_mangle]
|
||||
pub extern "C" fn remove(path: *const c_char) -> c_int {
|
||||
let r = platform::unlink(path);
|
||||
let r = Sys::unlink(path);
|
||||
if r == -errno::EISDIR {
|
||||
platform::rmdir(path)
|
||||
Sys::rmdir(path)
|
||||
} else {
|
||||
r
|
||||
}
|
||||
@@ -834,7 +838,7 @@ pub extern "C" fn remove(path: *const c_char) -> c_int {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn rename(oldpath: *const c_char, newpath: *const c_char) -> c_int {
|
||||
platform::rename(oldpath, newpath)
|
||||
Sys::rename(oldpath, newpath)
|
||||
}
|
||||
|
||||
/// Rewind `stream` back to the beginning of it
|
||||
@@ -908,10 +912,10 @@ pub extern "C" fn tmpfile() -> *mut FILE {
|
||||
}
|
||||
|
||||
let fp = fdopen(fd, b"w+".as_ptr() as *const i8);
|
||||
platform::unlink(file_name);
|
||||
Sys::unlink(file_name);
|
||||
|
||||
if fp == ptr::null_mut() {
|
||||
platform::close(fd);
|
||||
Sys::close(fd);
|
||||
}
|
||||
|
||||
fp
|
||||
|
||||
@@ -23,6 +23,7 @@ use wchar::*;
|
||||
|
||||
use errno::*;
|
||||
use fcntl::*;
|
||||
use platform::{Pal, Sys};
|
||||
use platform::types::*;
|
||||
|
||||
mod sort;
|
||||
@@ -235,7 +236,7 @@ pub unsafe extern "C" fn exit(status: c_int) {
|
||||
}
|
||||
}
|
||||
|
||||
platform::exit(status);
|
||||
Sys::exit(status);
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -446,7 +447,7 @@ where
|
||||
pub extern "C" fn mktemp(name: *mut c_char) -> *mut c_char {
|
||||
if inner_mktemp(name, 0, || unsafe {
|
||||
let mut st: stat = mem::uninitialized();
|
||||
let ret = if platform::stat(name, &mut st) != 0 && platform::errno == ENOENT {
|
||||
let ret = if Sys::stat(name, &mut st) != 0 && platform::errno == ENOENT {
|
||||
Some(())
|
||||
} else {
|
||||
None
|
||||
@@ -466,7 +467,7 @@ fn get_nstime() -> u64 {
|
||||
use core::mem;
|
||||
use time::constants::CLOCK_MONOTONIC;
|
||||
let mut ts: timespec = unsafe { mem::uninitialized() };
|
||||
platform::clock_gettime(CLOCK_MONOTONIC, &mut ts);
|
||||
Sys::clock_gettime(CLOCK_MONOTONIC, &mut ts);
|
||||
ts.tv_nsec as u64
|
||||
}
|
||||
|
||||
@@ -476,7 +477,7 @@ pub extern "C" fn mkostemps(name: *mut c_char, suffix_len: c_int, mut flags: c_i
|
||||
flags |= O_RDWR | O_CREAT | O_EXCL;
|
||||
|
||||
inner_mktemp(name, suffix_len, || {
|
||||
let fd = platform::open(name, flags, 0600);
|
||||
let fd = Sys::open(name, flags, 0600);
|
||||
|
||||
if fd >= 0 {
|
||||
Some(fd)
|
||||
@@ -1004,7 +1005,7 @@ pub unsafe extern "C" fn system(command: *const c_char) -> c_int {
|
||||
unreachable!();
|
||||
} else {
|
||||
let mut wstatus = 0;
|
||||
if platform::waitpid(child_pid, &mut wstatus, 0) == !0 {
|
||||
if Sys::waitpid(child_pid, &mut wstatus, 0) == !0 {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
extern crate platform;
|
||||
|
||||
use platform::{Pal, Sys};
|
||||
use platform::types::*;
|
||||
|
||||
// This is used from sgtty
|
||||
@@ -31,7 +32,7 @@ pub mod inner {
|
||||
#[no_mangle]
|
||||
pub extern "C" fn ioctl(fd: c_int, request: c_ulong, out: *mut c_void) -> c_int {
|
||||
// TODO: Somehow support varargs to syscall??
|
||||
platform::ioctl(fd, request, out)
|
||||
Sys::ioctl(fd, request, out)
|
||||
}
|
||||
|
||||
pub const TCGETS: c_ulong = 0x5401;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
extern crate platform;
|
||||
|
||||
use platform::{Pal, Sys};
|
||||
use platform::types::*;
|
||||
|
||||
pub use sys::*;
|
||||
@@ -33,7 +34,7 @@ pub unsafe extern "C" fn mmap(
|
||||
fildes: c_int,
|
||||
off: off_t,
|
||||
) -> *mut c_void {
|
||||
platform::mmap(addr, len, prot, flags, fildes, off)
|
||||
Sys::mmap(addr, len, prot, flags, fildes, off)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -58,7 +59,7 @@ pub extern "C" fn munlockall() -> c_int {
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn munmap(addr: *mut c_void, len: usize) -> c_int {
|
||||
platform::munmap(addr, len)
|
||||
Sys::munmap(addr, len)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
extern crate platform;
|
||||
extern crate sys_time;
|
||||
|
||||
use platform::{Pal, Sys};
|
||||
use platform::types::*;
|
||||
use sys_time::timeval;
|
||||
|
||||
@@ -55,7 +56,7 @@ pub unsafe extern "C" fn getrlimit(resource: c_int, rlp: *mut rlimit) -> c_int {
|
||||
|
||||
//#[no_mangle]
|
||||
pub unsafe extern "C" fn getrusage(who: c_int, r_usage: *mut rusage) -> c_int {
|
||||
platform::getrusage(who, r_usage as *mut platform::types::rusage)
|
||||
Sys::getrusage(who, r_usage as *mut platform::types::rusage)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
extern crate platform;
|
||||
|
||||
use core::mem;
|
||||
use platform::{Pal, Sys};
|
||||
use platform::types::*;
|
||||
|
||||
// fd_set is defined in C because cbindgen is incompatible with mem::size_of booo
|
||||
@@ -16,5 +17,5 @@ pub extern "C" fn select(
|
||||
exceptfds: *mut fd_set,
|
||||
timeout: *mut timeval,
|
||||
) -> c_int {
|
||||
platform::select(nfds, readfds, writefds, exceptfds, timeout)
|
||||
Sys::select(nfds, readfds, writefds, exceptfds, timeout)
|
||||
}
|
||||
|
||||
+14
-13
@@ -6,6 +6,7 @@
|
||||
extern crate platform;
|
||||
|
||||
use core::ptr;
|
||||
use platform::{PalSocket, Sys};
|
||||
use platform::types::*;
|
||||
|
||||
mod constants;
|
||||
@@ -28,7 +29,7 @@ pub unsafe extern "C" fn accept(
|
||||
address: *mut sockaddr,
|
||||
address_len: *mut socklen_t,
|
||||
) -> c_int {
|
||||
platform::accept(
|
||||
Sys::accept(
|
||||
socket,
|
||||
address as *mut platform::types::sockaddr,
|
||||
address_len,
|
||||
@@ -41,7 +42,7 @@ pub unsafe extern "C" fn bind(
|
||||
address: *const sockaddr,
|
||||
address_len: socklen_t,
|
||||
) -> c_int {
|
||||
platform::bind(
|
||||
Sys::bind(
|
||||
socket,
|
||||
address as *const platform::types::sockaddr,
|
||||
address_len,
|
||||
@@ -54,7 +55,7 @@ pub unsafe extern "C" fn connect(
|
||||
address: *const sockaddr,
|
||||
address_len: socklen_t,
|
||||
) -> c_int {
|
||||
platform::connect(
|
||||
Sys::connect(
|
||||
socket,
|
||||
address as *const platform::types::sockaddr,
|
||||
address_len,
|
||||
@@ -67,7 +68,7 @@ pub unsafe extern "C" fn getpeername(
|
||||
address: *mut sockaddr,
|
||||
address_len: *mut socklen_t,
|
||||
) -> c_int {
|
||||
platform::getpeername(
|
||||
Sys::getpeername(
|
||||
socket,
|
||||
address as *mut platform::types::sockaddr,
|
||||
address_len,
|
||||
@@ -80,7 +81,7 @@ pub unsafe extern "C" fn getsockname(
|
||||
address: *mut sockaddr,
|
||||
address_len: *mut socklen_t,
|
||||
) -> c_int {
|
||||
platform::getsockname(
|
||||
Sys::getsockname(
|
||||
socket,
|
||||
address as *mut platform::types::sockaddr,
|
||||
address_len,
|
||||
@@ -95,12 +96,12 @@ pub unsafe extern "C" fn getsockopt(
|
||||
option_value: *mut c_void,
|
||||
option_len: *mut socklen_t,
|
||||
) -> c_int {
|
||||
platform::getsockopt(socket, level, option_name, option_value, option_len)
|
||||
Sys::getsockopt(socket, level, option_name, option_value, option_len)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn listen(socket: c_int, backlog: c_int) -> c_int {
|
||||
platform::listen(socket, backlog)
|
||||
Sys::listen(socket, backlog)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -129,7 +130,7 @@ pub unsafe extern "C" fn recvfrom(
|
||||
address: *mut sockaddr,
|
||||
address_len: *mut socklen_t,
|
||||
) -> ssize_t {
|
||||
platform::recvfrom(
|
||||
Sys::recvfrom(
|
||||
socket,
|
||||
buffer,
|
||||
length,
|
||||
@@ -158,7 +159,7 @@ pub unsafe extern "C" fn sendto(
|
||||
dest_addr: *const sockaddr,
|
||||
dest_len: socklen_t,
|
||||
) -> ssize_t {
|
||||
platform::sendto(
|
||||
Sys::sendto(
|
||||
socket,
|
||||
message,
|
||||
length,
|
||||
@@ -176,17 +177,17 @@ pub unsafe extern "C" fn setsockopt(
|
||||
option_value: *const c_void,
|
||||
option_len: socklen_t,
|
||||
) -> c_int {
|
||||
platform::setsockopt(socket, level, option_name, option_value, option_len)
|
||||
Sys::setsockopt(socket, level, option_name, option_value, option_len)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn shutdown(socket: c_int, how: c_int) -> c_int {
|
||||
platform::shutdown(socket, how)
|
||||
Sys::shutdown(socket, how)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int {
|
||||
platform::socket(domain, kind, protocol)
|
||||
Sys::socket(domain, kind, protocol)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -196,5 +197,5 @@ pub unsafe extern "C" fn socketpair(
|
||||
protocol: c_int,
|
||||
socket_vector: *mut c_int,
|
||||
) -> c_int {
|
||||
platform::socketpair(domain, kind, protocol, socket_vector)
|
||||
Sys::socketpair(domain, kind, protocol, socket_vector)
|
||||
}
|
||||
|
||||
+10
-9
@@ -4,6 +4,7 @@
|
||||
|
||||
extern crate platform;
|
||||
|
||||
use platform::{Pal, Sys};
|
||||
use platform::types::*;
|
||||
|
||||
pub const S_IFMT: c_int = 0o0170000;
|
||||
@@ -59,17 +60,17 @@ pub struct stat {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn chmod(path: *const c_char, mode: mode_t) -> c_int {
|
||||
platform::chmod(path, mode)
|
||||
Sys::chmod(path, mode)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fchmod(fildes: c_int, mode: mode_t) -> c_int {
|
||||
platform::fchmod(fildes, mode)
|
||||
Sys::fchmod(fildes, mode)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fstat(fildes: c_int, buf: *mut platform::types::stat) -> c_int {
|
||||
platform::fstat(fildes, buf)
|
||||
Sys::fstat(fildes, buf)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -79,22 +80,22 @@ pub extern "C" fn __fxstat(_ver: c_int, fildes: c_int, buf: *mut platform::types
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn futimens(fd: c_int, times: *const timespec) -> c_int {
|
||||
platform::futimens(fd, times)
|
||||
Sys::futimens(fd, times)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn lstat(path: *const c_char, buf: *mut platform::types::stat) -> c_int {
|
||||
platform::lstat(path, buf)
|
||||
Sys::lstat(path, buf)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn mkdir(path: *const c_char, mode: mode_t) -> c_int {
|
||||
platform::mkdir(path, mode)
|
||||
Sys::mkdir(path, mode)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn mkfifo(path: *const c_char, mode: mode_t) -> c_int {
|
||||
platform::mkfifo(path, mode)
|
||||
Sys::mkfifo(path, mode)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -104,12 +105,12 @@ pub extern "C" fn mknod(path: *const c_char, mode: mode_t, dev: dev_t) -> c_int
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn stat(file: *const c_char, buf: *mut platform::types::stat) -> c_int {
|
||||
platform::stat(file, buf)
|
||||
Sys::stat(file, buf)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn umask(mask: mode_t) -> mode_t {
|
||||
platform::umask(mask)
|
||||
Sys::umask(mask)
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
extern crate platform;
|
||||
|
||||
use platform::{Pal, Sys};
|
||||
use platform::types::*;
|
||||
|
||||
pub const ITIMER_REAL: c_int = 0;
|
||||
@@ -36,7 +37,7 @@ pub struct fd_set {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn getitimer(which: c_int, value: *mut itimerval) -> c_int {
|
||||
platform::getitimer(which, value as *mut platform::types::itimerval)
|
||||
Sys::getitimer(which, value as *mut platform::types::itimerval)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -45,7 +46,7 @@ pub extern "C" fn setitimer(
|
||||
value: *const itimerval,
|
||||
ovalue: *mut itimerval,
|
||||
) -> c_int {
|
||||
platform::setitimer(
|
||||
Sys::setitimer(
|
||||
which,
|
||||
value as *const platform::types::itimerval,
|
||||
ovalue as *mut platform::types::itimerval,
|
||||
@@ -54,7 +55,7 @@ pub extern "C" fn setitimer(
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int {
|
||||
platform::gettimeofday(
|
||||
Sys::gettimeofday(
|
||||
tp as *mut platform::types::timeval,
|
||||
tzp as *mut platform::types::timezone,
|
||||
)
|
||||
@@ -83,7 +84,7 @@ pub unsafe extern "C" fn utimes(path: *const c_char, times: *const timeval) -> c
|
||||
tv_nsec: ((*times.offset(1)).tv_usec as i64) * 1000,
|
||||
},
|
||||
];
|
||||
platform::utimens(path, times_spec.as_ptr())
|
||||
Sys::utimens(path, times_spec.as_ptr())
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
extern crate platform;
|
||||
|
||||
use platform::{Pal, Sys};
|
||||
use platform::types::*;
|
||||
|
||||
#[repr(C)]
|
||||
@@ -16,5 +17,5 @@ pub struct tms {
|
||||
|
||||
//#[no_mangle]
|
||||
pub extern "C" fn times(out: *mut tms) -> clock_t {
|
||||
platform::times(out as *mut platform::types::tms)
|
||||
Sys::times(out as *mut platform::types::tms)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
mod inner {
|
||||
extern crate platform;
|
||||
|
||||
use self::platform::{Pal, Sys};
|
||||
use self::platform::types::*;
|
||||
|
||||
const UTSLENGTH: usize = 65;
|
||||
@@ -22,7 +23,7 @@ mod inner {
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn uname(uts: *mut utsname) -> c_int {
|
||||
platform::uname(uts as *mut platform::types::utsname)
|
||||
Sys::uname(uts as *mut platform::types::utsname)
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
extern crate platform;
|
||||
extern crate sys_resource;
|
||||
|
||||
use platform::{Pal, Sys};
|
||||
use platform::types::*;
|
||||
use sys_resource::rusage;
|
||||
|
||||
@@ -51,5 +52,5 @@ pub unsafe extern "C" fn wait3(
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t {
|
||||
platform::waitpid(pid, stat_loc, options)
|
||||
Sys::waitpid(pid, stat_loc, options)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
extern crate platform;
|
||||
|
||||
use platform::{Pal, Sys};
|
||||
use platform::types::*;
|
||||
|
||||
pub type cc_t = u8;
|
||||
@@ -25,12 +26,12 @@ pub struct termios {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn tcgetattr(fd: c_int, out: *mut termios) -> c_int {
|
||||
platform::tcgetattr(fd, out as *mut platform::types::termios)
|
||||
Sys::tcgetattr(fd, out as *mut platform::types::termios)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn tcsetattr(fd: c_int, act: c_int, value: *mut termios) -> c_int {
|
||||
platform::tcsetattr(fd, act, value as *mut platform::types::termios)
|
||||
Sys::tcsetattr(fd, act, value as *mut platform::types::termios)
|
||||
}
|
||||
|
||||
pub const VINTR: usize = 0;
|
||||
|
||||
+4
-3
@@ -15,6 +15,7 @@ use constants::*;
|
||||
use core::mem::transmute;
|
||||
use errno::EIO;
|
||||
use helpers::*;
|
||||
use platform::{Pal, Sys};
|
||||
use platform::types::*;
|
||||
|
||||
#[repr(C)]
|
||||
@@ -121,7 +122,7 @@ pub extern "C" fn clock_getres(clock_id: clockid_t, res: *mut timespec) -> c_int
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn clock_gettime(clock_id: clockid_t, tp: *mut timespec) -> c_int {
|
||||
platform::clock_gettime(clock_id, tp as *mut platform::types::timespec)
|
||||
Sys::clock_gettime(clock_id, tp as *mut platform::types::timespec)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -328,7 +329,7 @@ pub unsafe extern "C" fn mktime(t: *mut tm) -> time_t {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int {
|
||||
platform::nanosleep(
|
||||
Sys::nanosleep(
|
||||
rqtp as *const platform::types::timespec,
|
||||
rmtp as *mut platform::types::timespec,
|
||||
)
|
||||
@@ -361,7 +362,7 @@ pub extern "C" fn strptime(buf: *const c_char, format: *const c_char, tm: *mut t
|
||||
#[no_mangle]
|
||||
pub extern "C" fn time(tloc: *mut time_t) -> time_t {
|
||||
let mut ts: platform::types::timespec = Default::default();
|
||||
platform::clock_gettime(CLOCK_REALTIME, &mut ts);
|
||||
Sys::clock_gettime(CLOCK_REALTIME, &mut ts);
|
||||
unsafe {
|
||||
if !tloc.is_null() {
|
||||
*tloc = ts.tv_sec
|
||||
|
||||
@@ -2,13 +2,14 @@ use core::ptr;
|
||||
|
||||
use errno::ENOMEM;
|
||||
use platform;
|
||||
use platform::{Pal, Sys};
|
||||
use platform::types::*;
|
||||
|
||||
static mut BRK: *mut c_void = ptr::null_mut();
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn brk(addr: *mut c_void) -> c_int {
|
||||
BRK = platform::brk(addr);
|
||||
BRK = Sys::brk(addr);
|
||||
|
||||
if BRK < addr {
|
||||
platform::errno = ENOMEM;
|
||||
@@ -21,7 +22,7 @@ pub unsafe extern "C" fn brk(addr: *mut c_void) -> c_int {
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sbrk(incr: intptr_t) -> *mut c_void {
|
||||
if BRK == ptr::null_mut() {
|
||||
BRK = platform::brk(ptr::null_mut());
|
||||
BRK = Sys::brk(ptr::null_mut());
|
||||
}
|
||||
|
||||
let old_brk = BRK;
|
||||
@@ -29,7 +30,7 @@ pub unsafe extern "C" fn sbrk(incr: intptr_t) -> *mut c_void {
|
||||
if incr != 0 {
|
||||
let addr = old_brk.offset(incr);
|
||||
|
||||
BRK = platform::brk(addr);
|
||||
BRK = Sys::brk(addr);
|
||||
|
||||
if BRK < addr {
|
||||
platform::errno = ENOMEM;
|
||||
|
||||
+39
-38
@@ -10,6 +10,7 @@ extern crate sys_time;
|
||||
|
||||
use core::{ptr, slice};
|
||||
|
||||
use platform::{Pal, Sys};
|
||||
use platform::types::*;
|
||||
|
||||
pub use brk::*;
|
||||
@@ -42,12 +43,12 @@ const PATH_MAX: usize = 4096;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _exit(status: c_int) {
|
||||
platform::exit(status)
|
||||
Sys::exit(status)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn access(path: *const c_char, mode: c_int) -> c_int {
|
||||
platform::access(path, mode)
|
||||
Sys::access(path, mode)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -74,7 +75,7 @@ pub extern "C" fn alarm(seconds: c_uint) -> c_uint {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn chdir(path: *const c_char) -> c_int {
|
||||
platform::chdir(path)
|
||||
Sys::chdir(path)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -84,12 +85,12 @@ pub extern "C" fn chroot(path: *const c_char) -> c_int {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int {
|
||||
platform::chown(path, owner, group)
|
||||
Sys::chown(path, owner, group)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn close(fildes: c_int) -> c_int {
|
||||
platform::close(fildes)
|
||||
Sys::close(fildes)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -104,12 +105,12 @@ pub extern "C" fn crypt(key: *const c_char, salt: *const c_char) -> *mut c_char
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn dup(fildes: c_int) -> c_int {
|
||||
platform::dup(fildes)
|
||||
Sys::dup(fildes)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn dup2(fildes: c_int, fildes2: c_int) -> c_int {
|
||||
platform::dup2(fildes, fildes2)
|
||||
Sys::dup2(fildes, fildes2)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -147,7 +148,7 @@ pub unsafe extern "C" fn execve(
|
||||
argv: *const *mut c_char,
|
||||
envp: *const *mut c_char,
|
||||
) -> c_int {
|
||||
platform::execve(path, argv, envp)
|
||||
Sys::execve(path, argv, envp)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -157,12 +158,12 @@ pub extern "C" fn execvp(file: *const c_char, argv: *const *mut c_char) -> c_int
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int {
|
||||
platform::fchown(fildes, owner, group)
|
||||
Sys::fchown(fildes, owner, group)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fchdir(fildes: c_int) -> c_int {
|
||||
platform::fchdir(fildes)
|
||||
Sys::fchdir(fildes)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -172,17 +173,17 @@ pub extern "C" fn fdatasync(fildes: c_int) -> c_int {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fork() -> pid_t {
|
||||
platform::fork()
|
||||
Sys::fork()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fsync(fildes: c_int) -> c_int {
|
||||
platform::fsync(fildes)
|
||||
Sys::fsync(fildes)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn ftruncate(fildes: c_int, length: off_t) -> c_int {
|
||||
platform::ftruncate(fildes, length)
|
||||
Sys::ftruncate(fildes, length)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -194,7 +195,7 @@ pub extern "C" fn getcwd(mut buf: *mut c_char, mut size: size_t) -> *mut c_char
|
||||
size = stack_buf.len();
|
||||
}
|
||||
|
||||
let ret = platform::getcwd(buf, size);
|
||||
let ret = Sys::getcwd(buf, size);
|
||||
if ret == ptr::null_mut() {
|
||||
return ptr::null_mut();
|
||||
}
|
||||
@@ -220,17 +221,17 @@ pub extern "C" fn getdtablesize() -> c_int {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn getegid() -> gid_t {
|
||||
platform::getegid()
|
||||
Sys::getegid()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn geteuid() -> uid_t {
|
||||
platform::geteuid()
|
||||
Sys::geteuid()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn getgid() -> gid_t {
|
||||
platform::getgid()
|
||||
Sys::getgid()
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -245,7 +246,7 @@ pub extern "C" fn gethostid() -> c_long {
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn gethostname(name: *mut c_char, len: size_t) -> c_int {
|
||||
platform::gethostname(name, len)
|
||||
Sys::gethostname(name, len)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -270,22 +271,22 @@ pub extern "C" fn getpass(prompt: *const c_char) -> *mut c_char {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn getpgid(pid: pid_t) -> pid_t {
|
||||
platform::getpgid(pid)
|
||||
Sys::getpgid(pid)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn getpgrp() -> pid_t {
|
||||
platform::getpgid(platform::getpid())
|
||||
Sys::getpgid(Sys::getpid())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn getpid() -> pid_t {
|
||||
platform::getpid()
|
||||
Sys::getpid()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn getppid() -> pid_t {
|
||||
platform::getppid()
|
||||
Sys::getppid()
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -295,7 +296,7 @@ pub extern "C" fn getsid(pid: pid_t) -> pid_t {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn getuid() -> uid_t {
|
||||
platform::getuid()
|
||||
Sys::getuid()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -305,7 +306,7 @@ pub extern "C" fn getwd(path_name: *mut c_char) -> *mut c_char {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn isatty(fd: c_int) -> c_int {
|
||||
platform::isatty(fd)
|
||||
Sys::isatty(fd)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -315,7 +316,7 @@ pub extern "C" fn lchown(path: *const c_char, owner: uid_t, group: gid_t) -> c_i
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn link(path1: *const c_char, path2: *const c_char) -> c_int {
|
||||
platform::link(path1, path2)
|
||||
Sys::link(path1, path2)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -325,7 +326,7 @@ pub extern "C" fn lockf(fildes: c_int, function: c_int, size: off_t) -> c_int {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn lseek(fildes: c_int, offset: off_t, whence: c_int) -> off_t {
|
||||
platform::lseek(fildes, offset, whence)
|
||||
Sys::lseek(fildes, offset, whence)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -340,7 +341,7 @@ pub extern "C" fn pause() -> c_int {
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn pipe(fildes: *mut c_int) -> c_int {
|
||||
platform::pipe(slice::from_raw_parts_mut(fildes, 2))
|
||||
Sys::pipe(slice::from_raw_parts_mut(fildes, 2))
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -371,7 +372,7 @@ pub extern "C" fn pwrite(
|
||||
pub extern "C" fn read(fildes: c_int, buf: *const c_void, nbyte: size_t) -> ssize_t {
|
||||
use core::slice;
|
||||
let buf = unsafe { slice::from_raw_parts_mut(buf as *mut u8, nbyte as usize) };
|
||||
platform::read(fildes, buf)
|
||||
Sys::read(fildes, buf)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -381,17 +382,17 @@ pub extern "C" fn readlink(path: *const c_char, buf: *mut c_char, bufsize: size_
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn rmdir(path: *const c_char) -> c_int {
|
||||
platform::rmdir(path)
|
||||
Sys::rmdir(path)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn setgid(gid: gid_t) -> c_int {
|
||||
platform::setregid(gid, gid)
|
||||
Sys::setregid(gid, gid)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn setpgid(pid: pid_t, pgid: pid_t) -> c_int {
|
||||
platform::setpgid(pid, pgid)
|
||||
Sys::setpgid(pid, pgid)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -401,12 +402,12 @@ pub extern "C" fn setpgrp() -> pid_t {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn setregid(rgid: gid_t, egid: gid_t) -> c_int {
|
||||
platform::setregid(rgid, egid)
|
||||
Sys::setregid(rgid, egid)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn setreuid(ruid: uid_t, euid: uid_t) -> c_int {
|
||||
platform::setreuid(ruid, euid)
|
||||
Sys::setreuid(ruid, euid)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -416,7 +417,7 @@ pub extern "C" fn setsid() -> pid_t {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn setuid(uid: uid_t) -> c_int {
|
||||
platform::setreuid(uid, uid)
|
||||
Sys::setreuid(uid, uid)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -426,7 +427,7 @@ pub extern "C" fn sleep(seconds: c_uint) -> c_uint {
|
||||
tv_nsec: 0,
|
||||
};
|
||||
let rmtp = ptr::null_mut();
|
||||
platform::nanosleep(&rqtp, rmtp);
|
||||
Sys::nanosleep(&rqtp, rmtp);
|
||||
0
|
||||
}
|
||||
|
||||
@@ -502,7 +503,7 @@ pub extern "C" fn ualarm(value: useconds_t, interval: useconds_t) -> useconds_t
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn unlink(path: *const c_char) -> c_int {
|
||||
platform::unlink(path)
|
||||
Sys::unlink(path)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -512,7 +513,7 @@ pub extern "C" fn usleep(useconds: useconds_t) -> c_int {
|
||||
tv_nsec: ((useconds % 1000) * 1000) as i64,
|
||||
};
|
||||
let rmtp = ptr::null_mut();
|
||||
platform::nanosleep(&rqtp, rmtp)
|
||||
Sys::nanosleep(&rqtp, rmtp)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -525,7 +526,7 @@ pub extern "C" fn write(fildes: c_int, buf: *const c_void, nbyte: size_t) -> ssi
|
||||
use core::slice;
|
||||
|
||||
let buf = unsafe { slice::from_raw_parts(buf as *const u8, nbyte as usize) };
|
||||
platform::write(fildes, buf)
|
||||
Sys::write(fildes, buf)
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
extern crate platform;
|
||||
|
||||
use platform::{Pal, Sys};
|
||||
use platform::types::*;
|
||||
|
||||
#[repr(C)]
|
||||
@@ -25,5 +26,5 @@ pub unsafe extern "C" fn utime(filename: *const c_char, times: *const utimbuf) -
|
||||
tv_nsec: 0,
|
||||
},
|
||||
];
|
||||
platform::utimens(filename, times_spec.as_ptr())
|
||||
Sys::utimens(filename, times_spec.as_ptr())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user