From d4e583f8c425559e278f88fe751173ddccbcd508 Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <hch@cloudius-systems.com>
Date: Sat, 19 Jan 2013 19:38:31 +0100
Subject: [PATCH] add clock_gettime and supporting functionality

---
 libc/time.cc | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/libc/time.cc b/libc/time.cc
index 4262c9f23..2f3b5196b 100644
--- a/libc/time.cc
+++ b/libc/time.cc
@@ -1,4 +1,6 @@
 #include <sys/time.h>
+#include <time.h>
+#include "libc.hh"
 #include "drivers/clock.hh"
 #include "sched.hh"
 
@@ -25,3 +27,35 @@ int nanosleep(const struct timespec* req, struct timespec* rem)
     sched::thread::sleep_until(clock::get()->time() + convert(*req));
     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);
+}
-- 
GitLab