summaryrefslogtreecommitdiff
path: root/src/mytime.c
blob: ffb7323afbbf94d001766f9d4fee4c53b0a073f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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;
}