meta: move photon/libc to root
This commit is contained in:
78
libc/sys/horizon/time.c
Normal file
78
libc/sys/horizon/time.c
Normal file
@@ -0,0 +1,78 @@
|
||||
#include <magenta/types.h>
|
||||
#include <magenta/misc.h>
|
||||
#include <magenta/errors.h>
|
||||
#include <magenta/clock.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
||||
clock_t __sys_clock(void)
|
||||
{
|
||||
mx_time_val_t v;
|
||||
mx_clock_get_time(MX_CLOCK_MONOTONIC, &v);
|
||||
|
||||
return (v.sec * CLOCKS_PER_SEC) + v.nsec;
|
||||
}
|
||||
|
||||
time_t __sys_time(void)
|
||||
{
|
||||
mx_time_val_t v;
|
||||
mx_clock_get_time(MX_CLOCK_REALTIME, &v);
|
||||
|
||||
return v.sec;
|
||||
}
|
||||
|
||||
int nanosleep(const struct timespec *req, struct timespec *rem)
|
||||
{
|
||||
if (!req) {
|
||||
__set_errno(EFAULT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mx_nanosleep(mx_deadline_after(MX_SEC(req->tv_sec) + MX_NSEC(req->tv_nsec)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __sys_clock_getres(clockid_t clk_id, struct timespec *res)
|
||||
{
|
||||
mx_time_val_t v;
|
||||
mx_status_t s = mx_clock_get_resolution(clk_id, &v);
|
||||
|
||||
if (s != MX_OK) {
|
||||
/* TODO set errno */
|
||||
return -1;
|
||||
}
|
||||
|
||||
res->tv_sec = v.sec;
|
||||
res->tv_nsec = v.nsec;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __sys_clock_gettime(clockid_t clk_id, struct timespec *tp)
|
||||
{
|
||||
mx_time_val_t v;
|
||||
mx_status_t s = mx_clock_get_time(clk_id, &v);
|
||||
|
||||
if (s != MX_OK) {
|
||||
/* TODO set errno */
|
||||
return -1;
|
||||
}
|
||||
|
||||
tp->tv_sec = v.sec;
|
||||
tp->tv_nsec = v.nsec;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __sys_clock_settime(clockid_t clk_id, const struct timespec *tp)
|
||||
{
|
||||
mx_time_val_t v = { .sec = tp->tv_sec, .nsec = tp->tv_nsec };
|
||||
mx_status_t s = mx_clock_set_time(clk_id, &v);
|
||||
|
||||
if (s != MX_OK) {
|
||||
/* TODO set errno */
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user