Skip to content
Snippets Groups Projects
Commit d4e583f8 authored by Christoph Hellwig's avatar Christoph Hellwig
Browse files

add clock_gettime and supporting functionality

parent bb421a7f
No related branches found
No related tags found
No related merge requests found
#include <sys/time.h> #include <sys/time.h>
#include <time.h>
#include "libc.hh"
#include "drivers/clock.hh" #include "drivers/clock.hh"
#include "sched.hh" #include "sched.hh"
...@@ -25,3 +27,35 @@ int nanosleep(const struct timespec* req, struct timespec* rem) ...@@ -25,3 +27,35 @@ int nanosleep(const struct timespec* req, struct timespec* rem)
sched::thread::sleep_until(clock::get()->time() + convert(*req)); sched::thread::sleep_until(clock::get()->time() + convert(*req));
return 0; return 0;
} }
int clock_gettime(clockid_t clk_id, struct timespec* ts)
{
if (clk_id != CLOCK_REALTIME) {
return libc_error(EINVAL);
}
u64 time = clock::get()->time();
auto sec = time / 1000000000;
auto nsec = time % 1000000000;
ts->tv_sec = sec;
ts->tv_nsec = nsec;
return 0;
}
int clock_getres(clockid_t clk_id, struct timespec* ts)
{
if (clk_id != CLOCK_REALTIME) {
return libc_error(EINVAL);
}
if (ts) {
ts->tv_sec = 0;
ts->tv_nsec = 1;
}
return 0;
}
int clock_getcpuclockid(pid_t pid, clockid_t* clock_id)
{
return libc_error(ENOSYS);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment