summaryrefslogtreecommitdiff
path: root/qstd
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
parentae7824be86ecc53752a3bee1038c0677ac203cf7 (diff)
ui stuf and things hmm m mmm m シ
Diffstat (limited to 'qstd')
-rw-r--r--qstd/Makefile2
-rw-r--r--qstd/plat.c40
-rw-r--r--qstd/plat.h5
3 files changed, 43 insertions, 4 deletions
diff --git a/qstd/Makefile b/qstd/Makefile
index c4b088b..7e3f0f1 100644
--- a/qstd/Makefile
+++ b/qstd/Makefile
@@ -2,7 +2,7 @@
target = libqstd.a
includes = -I../qstd
defines = -Dplat_x86 -Dplat_posix -Dallocation_default_alignment=8
-cflags = -std=c90 -pedantic -Wall -Wextra $(DEBUG_COMPILE_FLAG) $(includes) $(defines)
+cflags = -std=gnu90 -pedantic -Wall -Wextra $(DEBUG_COMPILE_FLAG) $(includes) $(defines)
lflags = $(DEBUG_LINK_FLAG)
objects = plat.o memory.o str.o pack.o
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
diff --git a/qstd/plat.h b/qstd/plat.h
index 27521fa..b3715a3 100644
--- a/qstd/plat.h
+++ b/qstd/plat.h
@@ -1,6 +1,8 @@
#ifndef plat_h
#define plat_h
+#include <stdint.h>
+
#ifdef assert
#undef assert
#endif
@@ -29,4 +31,7 @@ void print_err(const char* fmt, ...);
void print_war(const char* fmt, ...);
void pbreak(int code);
+uint64_t get_time(void);
+
+
#endif