diff --git a/photon/libc/include/time.h b/photon/libc/include/time.h index 53d67fc..4a0976e 100644 --- a/photon/libc/include/time.h +++ b/photon/libc/include/time.h @@ -30,6 +30,8 @@ struct tm { extern clock_t clock(void); extern time_t time(time_t *p); +extern int nanosleep(const struct timespec *req, struct timespec *rem); + extern struct tm *gmtime(const time_t *timer); extern struct tm *localtime(const time_t *timer); extern time_t mktime(struct tm *timeptr); diff --git a/photon/libc/sys/horizon/time.c b/photon/libc/sys/horizon/time.c index 6705b2e..6aa78c6 100644 --- a/photon/libc/sys/horizon/time.c +++ b/photon/libc/sys/horizon/time.c @@ -1,7 +1,9 @@ #include +#include #include #include #include +#include clock_t __sys_clock(void) { @@ -19,6 +21,17 @@ time_t __sys_time(void) 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;