From 96b27fe9841e537614962e273ef9f0802365ea6d Mon Sep 17 00:00:00 2001 From: quou Date: Tue, 31 Dec 2024 23:38:11 +1100 Subject: ui stuf and things hmm m mmm m シ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qstd/plat.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'qstd/plat.c') 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 #include +#include +#include #include #include +#include #include -#include -#include 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 -- cgit v1.2.3-54-g00ecf