Implement utimes and utime
Format
This commit is contained in:
@@ -109,6 +109,10 @@ pub fn futimens(fd: c_int, times: *const timespec) -> c_int {
|
||||
e(unsafe { syscall!(UTIMENSAT, fd, ptr::null::<c_char>(), times, 0) }) as c_int
|
||||
}
|
||||
|
||||
pub fn utimens(path: *const c_char, times: *const timespec) -> c_int {
|
||||
e(unsafe { syscall!(UTIMENSAT, AT_FDCWD, path, times, 0) }) as c_int
|
||||
}
|
||||
|
||||
pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char {
|
||||
if e(unsafe { syscall!(GETCWD, buf, size) }) == !0 {
|
||||
ptr::null_mut()
|
||||
@@ -373,7 +377,13 @@ pub fn shutdown(socket: c_int, how: c_int) -> c_int {
|
||||
}
|
||||
|
||||
pub 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
|
||||
e(syscall!(
|
||||
RT_SIGACTION,
|
||||
sig,
|
||||
act,
|
||||
oact,
|
||||
mem::size_of::<sigset_t>()
|
||||
)) as c_int
|
||||
}
|
||||
|
||||
pub fn sigprocmask(how: c_int, set: *const sigset_t, oset: *mut sigset_t) -> c_int {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::{close, dup, open, types::*};
|
||||
use core::ops::Deref;
|
||||
use super::{open, dup, close, types::*};
|
||||
|
||||
pub struct RawFile(c_int);
|
||||
|
||||
@@ -7,14 +7,14 @@ impl RawFile {
|
||||
pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> Result<RawFile, ()> {
|
||||
match open(path, oflag, mode) {
|
||||
-1 => Err(()),
|
||||
n => Ok(RawFile(n))
|
||||
n => Ok(RawFile(n)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dup(&self) -> Result<RawFile, ()> {
|
||||
match dup(self.0) {
|
||||
-1 => Err(()),
|
||||
n => Ok(RawFile(n))
|
||||
n => Ok(RawFile(n)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -248,15 +248,15 @@ pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int {
|
||||
(*buf).st_blksize = redox_buf.st_blksize as blksize_t;
|
||||
(*buf).st_atim = timespec {
|
||||
tv_sec: redox_buf.st_atime as time_t,
|
||||
tv_nsec: 0
|
||||
tv_nsec: 0,
|
||||
};
|
||||
(*buf).st_mtim = timespec {
|
||||
tv_sec: redox_buf.st_mtime as time_t,
|
||||
tv_nsec: 0
|
||||
tv_nsec: 0,
|
||||
};
|
||||
(*buf).st_ctim = timespec {
|
||||
tv_sec: redox_buf.st_ctime as time_t,
|
||||
tv_nsec: 0
|
||||
tv_nsec: 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -275,13 +275,24 @@ pub fn ftruncate(fd: c_int, len: off_t) -> c_int {
|
||||
}
|
||||
|
||||
pub fn futimens(fd: c_int, times: *const timespec) -> c_int {
|
||||
let times = [
|
||||
unsafe { redox_timespec::from(&*times) },
|
||||
unsafe { redox_timespec::from(&*times.offset(1)) }
|
||||
];
|
||||
let times = [unsafe { redox_timespec::from(&*times) }, unsafe {
|
||||
redox_timespec::from(&*times.offset(1))
|
||||
}];
|
||||
e(syscall::futimens(fd as usize, ×)) as c_int
|
||||
}
|
||||
|
||||
pub fn utimens(path: *const c_char, times: *const timespec) -> c_int {
|
||||
let path = unsafe { c_str(path) };
|
||||
match syscall::open(path, O_STAT) {
|
||||
Err(err) => e(Err(err)) as c_int,
|
||||
Ok(fd) => {
|
||||
let res = futimens(fd, times);
|
||||
let _ = syscall::close(fd);
|
||||
res
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char {
|
||||
let buf_slice = unsafe { slice::from_raw_parts_mut(buf as *mut u8, size as usize) };
|
||||
if e(syscall::getcwd(buf_slice)) == !0 {
|
||||
@@ -307,7 +318,7 @@ pub fn getdents(fd: c_int, mut dirents: *mut dirent, mut bytes: usize) -> c_int
|
||||
blen = match syscall::read(fd as usize, &mut buf) {
|
||||
Ok(0) => return amount,
|
||||
Ok(n) => n,
|
||||
Err(err) => return -err.errno
|
||||
Err(err) => return -err.errno,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -320,7 +331,7 @@ pub fn getdents(fd: c_int, mut dirents: *mut dirent, mut bytes: usize) -> c_int
|
||||
d_off: 0,
|
||||
d_reclen: mem::size_of::<dirent>() as c_ushort,
|
||||
d_type: 0,
|
||||
d_name: name
|
||||
d_name: name,
|
||||
};
|
||||
dirents = dirents.offset(1);
|
||||
}
|
||||
@@ -474,7 +485,10 @@ pub fn getsockopt(
|
||||
|
||||
pub fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int {
|
||||
let mut redox_tp = redox_timespec::default();
|
||||
let err = e(syscall::clock_gettime(syscall::CLOCK_REALTIME, &mut redox_tp)) as c_int;
|
||||
let err = e(syscall::clock_gettime(
|
||||
syscall::CLOCK_REALTIME,
|
||||
&mut redox_tp,
|
||||
)) as c_int;
|
||||
if err < 0 {
|
||||
return err;
|
||||
}
|
||||
@@ -532,7 +546,7 @@ pub fn lseek(fd: c_int, offset: off_t, whence: c_int) -> 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) {
|
||||
match syscall::open(path, O_STAT | O_NOFOLLOW) {
|
||||
Err(err) => e(Err(err)) as c_int,
|
||||
Ok(fd) => {
|
||||
let res = fstat(fd as i32, buf);
|
||||
@@ -737,14 +751,14 @@ pub unsafe fn sigaction(sig: c_int, act: *const sigaction, oact: *mut sigaction)
|
||||
Some(syscall::SigAction {
|
||||
sa_handler: sig_handler,
|
||||
sa_mask: [0, m as u64],
|
||||
sa_flags: (*act).sa_flags as usize
|
||||
sa_flags: (*act).sa_flags as usize,
|
||||
})
|
||||
};
|
||||
let mut old = syscall::SigAction::default();
|
||||
let ret = e(syscall::sigaction(
|
||||
sig as usize,
|
||||
act.as_ref(),
|
||||
if oact.is_null() { None } else { Some(&mut old) }
|
||||
if oact.is_null() { None } else { Some(&mut old) },
|
||||
)) as c_int;
|
||||
if !oact.is_null() {
|
||||
let m = old.sa_mask;
|
||||
@@ -767,7 +781,7 @@ pub fn sigprocmask(how: c_int, set: *const sigset_t, oset: *mut sigset_t) -> c_i
|
||||
|
||||
pub fn stat(path: *const c_char, buf: *mut stat) -> c_int {
|
||||
let path = unsafe { c_str(path) };
|
||||
match syscall::open(path, O_RDONLY) {
|
||||
match syscall::open(path, O_STAT) {
|
||||
Err(err) => e(Err(err)) as c_int,
|
||||
Ok(fd) => {
|
||||
let res = fstat(fd as i32, buf);
|
||||
@@ -822,11 +836,7 @@ pub fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *m
|
||||
}
|
||||
|
||||
pub fn times(out: *mut tms) -> clock_t {
|
||||
let _ = write!(
|
||||
::FileWriter(2),
|
||||
"unimplemented: times({:p})",
|
||||
out
|
||||
);
|
||||
let _ = write!(::FileWriter(2), "unimplemented: times({:p})", out);
|
||||
!0
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use core::mem;
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
use syscall::data::TimeSpec as redox_timespec;
|
||||
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
|
||||
@@ -127,7 +125,7 @@ pub struct stat {
|
||||
// Compared to glibc, our struct is for some reason 24 bytes too small.
|
||||
// Accessing atime works, so clearly the struct isn't incorrect...
|
||||
// This works.
|
||||
pub _pad: [c_char; 24]
|
||||
pub _pad: [c_char; 24],
|
||||
}
|
||||
|
||||
pub const AF_INET: c_int = 2;
|
||||
@@ -154,14 +152,14 @@ pub struct sockaddr {
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct in_addr {
|
||||
pub s_addr: in_addr_t
|
||||
pub s_addr: in_addr_t,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct sockaddr_in {
|
||||
pub sin_family: sa_family_t,
|
||||
pub sin_port: in_port_t,
|
||||
pub sin_addr: in_addr
|
||||
pub sin_addr: in_addr,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@@ -169,7 +167,7 @@ pub struct sigaction {
|
||||
pub sa_handler: extern "C" fn(c_int),
|
||||
pub sa_flags: c_ulong,
|
||||
pub sa_restorer: unsafe extern "C" fn(),
|
||||
pub sa_mask: sigset_t
|
||||
pub sa_mask: sigset_t,
|
||||
}
|
||||
|
||||
pub type sigset_t = c_ulong;
|
||||
@@ -192,7 +190,7 @@ pub struct dirent {
|
||||
pub d_off: off_t,
|
||||
pub d_reclen: c_ushort,
|
||||
pub d_type: c_uchar,
|
||||
pub d_name: [c_char; 256]
|
||||
pub d_name: [c_char; 256],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@@ -201,7 +199,7 @@ pub struct winsize {
|
||||
ws_row: c_ushort,
|
||||
ws_col: c_ushort,
|
||||
ws_xpixel: c_ushort,
|
||||
ws_ypixel: c_ushort
|
||||
ws_ypixel: c_ushort,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@@ -221,7 +219,7 @@ pub struct rusage {
|
||||
pub ru_msgrcv: c_long,
|
||||
pub ru_nsignals: c_long,
|
||||
pub ru_nvcsw: c_long,
|
||||
pub ru_nivcsw: c_long
|
||||
pub ru_nivcsw: c_long,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@@ -229,5 +227,5 @@ pub struct tms {
|
||||
tms_utime: clock_t,
|
||||
tms_stime: clock_t,
|
||||
tms_cutime: clock_t,
|
||||
tms_cstime: clock_t
|
||||
tms_cstime: clock_t,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user