This source file includes following definitions.
- timespec_sub
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #include <config.h>
25 #include "timespec.h"
26
27 #include <stdckdint.h>
28 #include "intprops.h"
29
30 struct timespec
31 timespec_sub (struct timespec a, struct timespec b)
32 {
33 time_t rs = a.tv_sec;
34 time_t bs = b.tv_sec;
35 int ns = a.tv_nsec - b.tv_nsec;
36 int rns = ns;
37
38 if (ns < 0)
39 {
40 rns = ns + TIMESPEC_HZ;
41 time_t bs1;
42 if (!ckd_add (&bs1, bs, 1))
43 bs = bs1;
44 else if (- TYPE_SIGNED (time_t) < rs)
45 rs--;
46 else
47 goto low_overflow;
48 }
49
50 if (ckd_sub (&rs, rs, bs))
51 {
52 if (0 < bs)
53 {
54 low_overflow:
55 rs = TYPE_MINIMUM (time_t);
56 rns = 0;
57 }
58 else
59 {
60 rs = TYPE_MAXIMUM (time_t);
61 rns = TIMESPEC_HZ - 1;
62 }
63 }
64
65 return make_timespec (rs, rns);
66 }