summaryrefslogtreecommitdiff
path: root/userland/libc/time
diff options
context:
space:
mode:
Diffstat (limited to 'userland/libc/time')
-rw-r--r--userland/libc/time/clock_gettime.c14
-rw-r--r--userland/libc/time/ctime_r.c13
-rw-r--r--userland/libc/time/gmtime.c21
-rw-r--r--userland/libc/time/localtime.c21
-rw-r--r--userland/libc/time/strftime.c7
-rw-r--r--userland/libc/time/time.c9
6 files changed, 85 insertions, 0 deletions
diff --git a/userland/libc/time/clock_gettime.c b/userland/libc/time/clock_gettime.c
new file mode 100644
index 0000000..15f0cb7
--- /dev/null
+++ b/userland/libc/time/clock_gettime.c
@@ -0,0 +1,14 @@
+#include <syscall.h>
+#include <time.h>
+
+int clock_gettime(clockid_t clock_id, struct timespec *tp) {
+ tp->tv_sec = 0;
+ tp->tv_nsec = 0;
+ return 0;
+ /*
+SYS_CLOCK_GETTIME_PARAMS args = {
+.clk = clock_id,
+.ts = tp,
+};
+return syscall(SYS_CLOCK_GETTIME, &args);*/
+}
diff --git a/userland/libc/time/ctime_r.c b/userland/libc/time/ctime_r.c
new file mode 100644
index 0000000..66e6416
--- /dev/null
+++ b/userland/libc/time/ctime_r.c
@@ -0,0 +1,13 @@
+#include <string.h>
+#include <time.h>
+
+// TODO: Implement this
+
+// Time, formatting and parsing are some of the most annoying parts of
+// programming. Lets just hope this function is not important
+char *ctime_r(const time_t *clock, char *buf) {
+ (void)clock;
+ size_t l = strlen(buf);
+ memset(buf, '0', l);
+ return buf;
+}
diff --git a/userland/libc/time/gmtime.c b/userland/libc/time/gmtime.c
new file mode 100644
index 0000000..44e0ff3
--- /dev/null
+++ b/userland/libc/time/gmtime.c
@@ -0,0 +1,21 @@
+#include <time.h>
+
+struct tm gmtime_r = {
+ .tm_sec = 0,
+ .tm_min = 0,
+ .tm_hour = 0,
+ .tm_mday = 0,
+ .tm_mon = 0,
+ .tm_year = 0,
+ .tm_wday = 0,
+ .tm_yday = 0,
+ .tm_isdst = 0,
+ .__tm_gmtoff = 0,
+ .__tm_zone = 0,
+};
+
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/gmtime.html
+struct tm *gmtime(const time_t *timer) {
+ // TODO: Implement
+ return &gmtime_r;
+}
diff --git a/userland/libc/time/localtime.c b/userland/libc/time/localtime.c
new file mode 100644
index 0000000..40ca351
--- /dev/null
+++ b/userland/libc/time/localtime.c
@@ -0,0 +1,21 @@
+#include <time.h>
+
+ struct tm localtime_r = {
+ .tm_sec = 0,
+ .tm_min = 0,
+ .tm_hour = 0,
+ .tm_mday = 0,
+ .tm_mon = 0,
+ .tm_year = 0,
+ .tm_wday = 0,
+ .tm_yday = 0,
+ .tm_isdst = 0,
+ .__tm_gmtoff = 0,
+ .__tm_zone = 0,
+ };
+
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/localtime.html
+struct tm *localtime(const time_t *timer) {
+ // TODO: Implement
+ return &localtime_r;
+}
diff --git a/userland/libc/time/strftime.c b/userland/libc/time/strftime.c
new file mode 100644
index 0000000..30a080d
--- /dev/null
+++ b/userland/libc/time/strftime.c
@@ -0,0 +1,7 @@
+#include <time.h>
+#include <stddef.h>
+
+size_t strftime(char *restrict s, size_t maxsize,
+ const char *restrict format, const struct tm *restrict timeptr) {
+ return 0;
+}
diff --git a/userland/libc/time/time.c b/userland/libc/time/time.c
new file mode 100644
index 0000000..9931b71
--- /dev/null
+++ b/userland/libc/time/time.c
@@ -0,0 +1,9 @@
+#include <time.h>
+
+time_t time(time_t *tloc) {
+ struct timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+ if (tloc)
+ *tloc = ts.tv_sec;
+ return ts.tv_sec;
+}