checktime.c 358 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <time.h>
#include <string.h>

#include "../util.h"

int checktime(time_t min)
{
	static struct timespec prev = {};
	time_t delta;
	struct timespec t;
	clock_gettime(CLOCK_MONOTONIC, &t);
	if (t.tv_sec < prev.tv_sec)
		delta = min;
	else
		delta = t.tv_sec - prev.tv_sec;
	if (delta < min)
		return 1;
	memcpy(&prev, &t, sizeof(prev));
	return 0;
}