This source file includes following definitions.
- make_timespec
- timespec_cmp
- timespec_sign
- timespec_add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #if ! defined TIMESPEC_H
20 #define TIMESPEC_H
21
22 #include <time.h>
23
24 #ifndef _GL_INLINE_HEADER_BEGIN
25 #error "Please include config.h first."
26 #endif
27 _GL_INLINE_HEADER_BEGIN
28 #ifndef _GL_TIMESPEC_INLINE
29 # define _GL_TIMESPEC_INLINE _GL_INLINE
30 #endif
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 #include "arg-nonnull.h"
37
38
39
40
41 enum { TIMESPEC_HZ = 1000000000 };
42 enum { LOG10_TIMESPEC_HZ = 9 };
43
44
45
46
47 enum { TIMESPEC_RESOLUTION = TIMESPEC_HZ };
48 enum { LOG10_TIMESPEC_RESOLUTION = LOG10_TIMESPEC_HZ };
49
50
51
52 _GL_TIMESPEC_INLINE struct timespec
53 make_timespec (time_t s, long int ns)
54 {
55 struct timespec r;
56 r.tv_sec = s;
57 r.tv_nsec = ns;
58 return r;
59 }
60
61
62
63 _GL_TIMESPEC_INLINE int _GL_ATTRIBUTE_PURE
64 timespec_cmp (struct timespec a, struct timespec b)
65 {
66 return 2 * _GL_CMP (a.tv_sec, b.tv_sec) + _GL_CMP (a.tv_nsec, b.tv_nsec);
67 }
68
69
70
71 _GL_TIMESPEC_INLINE int _GL_ATTRIBUTE_PURE
72 timespec_sign (struct timespec a)
73 {
74 return _GL_CMP (a.tv_sec, 0) + (!a.tv_sec & !!a.tv_nsec);
75 }
76
77 struct timespec timespec_add (struct timespec, struct timespec)
78 _GL_ATTRIBUTE_CONST;
79 struct timespec timespec_sub (struct timespec, struct timespec)
80 _GL_ATTRIBUTE_CONST;
81 struct timespec dtotimespec (double)
82 _GL_ATTRIBUTE_CONST;
83
84
85 _GL_TIMESPEC_INLINE double
86 timespectod (struct timespec a)
87 {
88 return a.tv_sec + a.tv_nsec / 1e9;
89 }
90
91 struct timespec current_timespec (void);
92 void gettime (struct timespec *) _GL_ARG_NONNULL ((1));
93 int settime (struct timespec const *) _GL_ARG_NONNULL ((1));
94
95 #ifdef __cplusplus
96 }
97 #endif
98
99 _GL_INLINE_HEADER_END
100
101 #endif