Merge branch 'master' into stat
This commit is contained in:
+10
-2
@@ -61,8 +61,8 @@ pub unsafe fn cstr_from_bytes_with_nul_unchecked(bytes: &[u8]) -> *const c_char
|
||||
pub struct FileWriter(pub c_int);
|
||||
|
||||
impl FileWriter {
|
||||
pub fn write(&mut self, buf: &[u8]) {
|
||||
write(self.0, buf);
|
||||
pub fn write(&mut self, buf: &[u8]) -> isize {
|
||||
write(self.0, buf)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +73,14 @@ impl fmt::Write for FileWriter {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FileReader(pub c_int);
|
||||
|
||||
impl FileReader {
|
||||
pub fn read(&mut self, buf: &mut [u8]) -> isize {
|
||||
read(self.0, buf)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct StringWriter(pub *mut u8, pub usize);
|
||||
|
||||
impl StringWriter {
|
||||
|
||||
@@ -130,10 +130,22 @@ pub fn getuid() -> uid_t {
|
||||
e(unsafe { syscall!(GETUID) })
|
||||
}
|
||||
|
||||
pub fn kill(pid: pid_t, sig: c_int) -> c_int {
|
||||
e(unsafe { syscall!(KILL, pid, sig) }) as c_int
|
||||
}
|
||||
|
||||
pub fn killpg(pgrp: pid_t, sig: c_int) -> c_int {
|
||||
e(unsafe { syscall!(KILL, -(pgrp as isize) as pid_t, sig) }) as c_int
|
||||
}
|
||||
|
||||
pub 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
|
||||
}
|
||||
|
||||
pub fn lseek(fildes: c_int, offset: off_t, whence: c_int) -> off_t {
|
||||
e(unsafe { syscall!(LSEEK, fildes, offset, whence) }) as off_t
|
||||
}
|
||||
|
||||
pub fn lstat(file: *const c_char, buf: *mut stat) -> c_int {
|
||||
e(unsafe { syscall!(NEWFSTATAT, AT_FDCWD, file, buf, AT_SYMLINK_NOFOLLOW) }) as c_int
|
||||
}
|
||||
@@ -189,3 +201,7 @@ pub fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t {
|
||||
pub fn write(fildes: c_int, buf: &[u8]) -> ssize_t {
|
||||
e(unsafe { syscall!(WRITE, fildes, buf.as_ptr(), buf.len()) }) as ssize_t
|
||||
}
|
||||
|
||||
pub fn clock_gettime(clk_id: clockid_t, tp: *mut timespec) -> c_int {
|
||||
e(unsafe { syscall!(CLOCK_GETTIME, clk_id, tp) }) as c_int
|
||||
}
|
||||
|
||||
@@ -169,12 +169,28 @@ pub fn getuid() -> uid_t {
|
||||
e(syscall::getuid()) as pid_t
|
||||
}
|
||||
|
||||
pub fn kill(pid: pid_t, sig: c_int) -> c_int {
|
||||
e(syscall::kill(pid, sig as usize)) as c_int
|
||||
}
|
||||
|
||||
pub fn killpg(pgrp: pid_t, sig: c_int) -> c_int {
|
||||
e(syscall::kill(-(pgrp as isize) as pid_t, sig as usize)) as c_int
|
||||
}
|
||||
|
||||
pub fn link(path1: *const c_char, path2: *const c_char) -> c_int {
|
||||
let path1 = unsafe { c_str(path1) };
|
||||
let path2 = unsafe { c_str(path2) };
|
||||
e(unsafe { syscall::link(path1.as_ptr(), path2.as_ptr()) }) as c_int
|
||||
}
|
||||
|
||||
pub fn lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t {
|
||||
e(syscall::lseek(
|
||||
fd as usize,
|
||||
offset as isize,
|
||||
whence as usize,
|
||||
)) as off_t
|
||||
}
|
||||
|
||||
pub fn lstat(path: *const c_char, buf: *mut stat) -> c_int {
|
||||
let path = unsafe { c_str(path) };
|
||||
match syscall::open(path, O_RDONLY | O_NOFOLLOW) {
|
||||
@@ -185,7 +201,6 @@ pub fn lstat(path: *const c_char, buf: *mut stat) -> c_int {
|
||||
res
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int {
|
||||
let flags = O_CREAT | O_EXCL | O_CLOEXEC | O_DIRECTORY | mode as usize & 0o777;
|
||||
@@ -286,3 +301,17 @@ pub fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t {
|
||||
pub fn write(fd: c_int, buf: &[u8]) -> ssize_t {
|
||||
e(syscall::write(fd as usize, buf)) as ssize_t
|
||||
}
|
||||
|
||||
pub fn clock_gettime(clk_id: clockid_t, tp: *mut timespec) -> c_int {
|
||||
let mut redox_tp = unsafe { redox_timespec::from(&*tp) };
|
||||
match e(syscall::clock_gettime(clk_id as usize, &mut redox_tp)) as c_int {
|
||||
-1 => -1,
|
||||
_ => {
|
||||
unsafe {
|
||||
(*tp).tv_sec = redox_tp.tv_sec;
|
||||
(*tp).tv_nsec = redox_tp.tv_nsec as i64;
|
||||
};
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ pub type clockid_t = i32;
|
||||
pub type timer_t = c_void;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Default)]
|
||||
pub struct timespec {
|
||||
pub tv_sec: time_t,
|
||||
pub tv_nsec: c_long,
|
||||
|
||||
Reference in New Issue
Block a user