summaryrefslogtreecommitdiff
path: root/src/mytime.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mytime.c')
-rw-r--r--src/mytime.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/mytime.c b/src/mytime.c
new file mode 100644
index 0000000..ffb7323
--- /dev/null
+++ b/src/mytime.c
@@ -0,0 +1,38 @@
+#include "mytime.h"
+
+#include <assert.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+bool fake_time;
+struct timespec global_time;
+
+struct timespec get_current_time() {
+ if(fake_time) {
+ return global_time;
+ }
+
+ struct timespec val;
+ if(clock_gettime(CLOCK_REALTIME, &val) != 0) {
+ abort();
+ }
+
+ return val;
+}
+
+void enable_fake_time() {
+ assert(!fake_time);
+
+ global_time = (struct timespec){
+ .tv_sec = 0,
+ .tv_nsec = 0,
+ };
+ fake_time = true;
+}
+
+void progress_time(uint64_t diff) {
+ assert(fake_time);
+
+ // Right now the diff is only seconds resolution
+ global_time.tv_sec += diff;
+}