summaryrefslogtreecommitdiff
path: root/qstd/plat.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-12-31 23:38:11 +1100
committerquou <quou@disroot.org>2024-12-31 23:38:11 +1100
commit96b27fe9841e537614962e273ef9f0802365ea6d (patch)
treed1373862f700a83dd476555913b50c969159a836 /qstd/plat.c
parentae7824be86ecc53752a3bee1038c0677ac203cf7 (diff)
ui stuf and things hmm m mmm m シ
Diffstat (limited to 'qstd/plat.c')
-rw-r--r--qstd/plat.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/qstd/plat.c b/qstd/plat.c
index 7f07b96..15e0265 100644
--- a/qstd/plat.c
+++ b/qstd/plat.c
@@ -1,15 +1,21 @@
#include "plat.h"
#ifdef plat_posix
+#ifndef _POSIX_SOURCE
#define _POSIX_SOURCE
+#endif
+#ifndef _GNU_SOURCE
#define _GNU_SOURCE
+#endif
+#include <aio.h>
#include <fcntl.h>
+#include <stdarg.h>
+#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
+#include <sys/types.h>
#include <time.h>
-#include <stdarg.h>
-#include <stdio.h>
extern int isatty(int);
extern int fileno(FILE*);
@@ -83,6 +89,34 @@ void pbreak(int code) {
#endif
}
+static clockid_t global_clock;
+static unsigned long global_freq;
+static int time_init = 0;
+
+void init_timer(void) {
+ struct timespec ts;
+ global_clock = CLOCK_REALTIME;
+ global_freq = 1000000000;
+ time_init = 1;
+#if defined(_POSIX_MONOTONIC_CLOCK)
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
+ global_clock = CLOCK_MONOTONIC;
+ }
+#else
+ (void)ts;
+#endif
+}
+
+uint64_t get_time(void) {
+ struct timespec ts;
+ if (!time_init)
+ init_timer();
+ clock_gettime(global_clock, &ts);
+ return
+ (uint64_t)ts.tv_sec * global_freq +
+ (uint64_t)ts.tv_nsec;
+}
+
#endif
#ifdef plat_win
@@ -153,4 +187,4 @@ void pbreak(int code) {
}
-#endif \ No newline at end of file
+#endif