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