1 contributor
38 lines1.1 KB
Newer
Older
-
+
commited
{line.log.rev}
on
8 months ago
22
1
#include <time.h>
2
3
static inline bool timespec_lt(struct timespec a, struct timespec b){
4
return a.tv_sec < b.tv_sec || (a.tv_sec == b.tv_sec && a.tv_nsec < b.tv_nsec);
5
}
6
7
static inline bool timespec_lte(struct timespec a, struct timespec b){
8
return a.tv_sec < b.tv_sec || (a.tv_sec == b.tv_sec && a.tv_nsec <= b.tv_nsec);
9
}
10
11
static inline bool timespec_eq(struct timespec a, struct timespec b){
12
return a.tv_sec == b.tv_sec && a.tv_nsec == b.tv_nsec;
13
}
14
15
static inline bool timespec_gt(struct timespec a, struct timespec b){
16
return timespec_lt(b, a);
17
}
18
19
static inline struct timespec timespec_sub(struct timespec a, struct timespec b){
20
struct timespec r;
21
if (a.tv_nsec < b.tv_nsec){
22
r.tv_nsec = 1000000000 + a.tv_nsec - b.tv_nsec;
23
r.tv_sec = a.tv_sec - b.tv_sec - 1;
24
} else {
25
r.tv_nsec = a.tv_nsec - b.tv_nsec;
26
r.tv_sec = a.tv_sec - b.tv_sec;
27
}
28
return r;
29
}
30
31
static inline bool timespec_gte(struct timespec a, struct timespec b){
32
return timespec_lte(b, a);
33
}
34
35
static inline bool timespec_ne(struct timespec a, struct timespec b){
36
return !timespec_eq(a, b);
37
}
38