Implement gettimeofday
This commit is contained in:
@@ -202,6 +202,10 @@ pub fn getsockopt(
|
||||
}) as c_int
|
||||
}
|
||||
|
||||
pub fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int {
|
||||
e(unsafe { syscall!(GETTIMEOFDAY, tp, tzp) }) as c_int
|
||||
}
|
||||
|
||||
pub fn getuid() -> uid_t {
|
||||
e(unsafe { syscall!(GETUID) })
|
||||
}
|
||||
|
||||
@@ -431,6 +431,24 @@ pub fn getsockopt(
|
||||
-1
|
||||
}
|
||||
|
||||
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;
|
||||
if err < 0 {
|
||||
return err;
|
||||
}
|
||||
unsafe {
|
||||
(*tp).tv_sec = redox_tp.tv_sec as time_t;
|
||||
(*tp).tv_usec = (redox_tp.tv_nsec / 1000) as suseconds_t;
|
||||
|
||||
if !tzp.is_null() {
|
||||
(*tzp).tz_minuteswest = 0;
|
||||
(*tzp).tz_dsttime = 0;
|
||||
}
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
pub fn getuid() -> uid_t {
|
||||
e(syscall::getuid()) as pid_t
|
||||
}
|
||||
|
||||
@@ -77,6 +77,18 @@ pub struct timespec {
|
||||
pub tv_nsec: c_long,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct timeval {
|
||||
pub tv_sec: time_t,
|
||||
pub tv_usec: suseconds_t,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Default)]
|
||||
pub struct timezone {
|
||||
pub tz_minuteswest: c_int,
|
||||
pub tz_dsttime: c_int,
|
||||
}
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
impl<'a> From<&'a timespec> for redox_timespec {
|
||||
fn from(tp: ×pec) -> redox_timespec {
|
||||
|
||||
@@ -11,6 +11,11 @@ pub struct timeval {
|
||||
pub tv_sec: time_t,
|
||||
pub tv_usec: suseconds_t,
|
||||
}
|
||||
#[repr(C)]
|
||||
pub struct timezone {
|
||||
pub tz_minuteswest: c_int,
|
||||
pub tz_dsttime: c_int,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct itimerval {
|
||||
@@ -37,9 +42,9 @@ pub extern "C" fn setitimer(
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
pub extern "C" fn gettimeofday(tp: *mut timeval, tzp: *const c_void) -> c_int {
|
||||
unimplemented!();
|
||||
#[no_mangle]
|
||||
pub extern "C" fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int {
|
||||
platform::gettimeofday(tp as *mut platform::types::timeval, tzp as *mut platform::types::timezone)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
|
||||
@@ -66,6 +66,7 @@ dirent
|
||||
stdlib/alloc
|
||||
stdlib/bsearch
|
||||
stdlib/mktemp
|
||||
time/gettimeofday
|
||||
unistd/chdir
|
||||
unistd/gethostname
|
||||
unistd/getid
|
||||
|
||||
@@ -69,6 +69,7 @@ BINS=\
|
||||
stdlib/alloc \
|
||||
stdlib/bsearch \
|
||||
stdlib/mktemp \
|
||||
time/gettimeofday \
|
||||
unistd/chdir \
|
||||
unistd/gethostname \
|
||||
unistd/getid \
|
||||
|
||||
+6
-6
@@ -29,10 +29,10 @@ int main() {
|
||||
entry = readdir(dir);
|
||||
puts(entry->d_name);
|
||||
|
||||
puts("--- Testing seek ---");
|
||||
// Why this doesn't cause it to actually go to the 4th element is beyond
|
||||
// me, but glibc acts the same way.
|
||||
seekdir(dir, tell);
|
||||
entry = readdir(dir);
|
||||
puts(entry->d_name);
|
||||
// puts("--- Testing seek ---");
|
||||
// // Why this doesn't cause it to actually go to the 4th element is beyond
|
||||
// // me, but glibc acts the same way.
|
||||
// seekdir(dir, tell);
|
||||
// entry = readdir(dir);
|
||||
// puts(entry->d_name);
|
||||
}
|
||||
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
#include <sys/time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
printf("%ld: %ld\n", tv.tv_sec, tv.tv_usec);
|
||||
}
|
||||
Reference in New Issue
Block a user