22 #ifndef LELY_UTIL_TIME_H_ 23 #define LELY_UTIL_TIME_H_ 29 #ifndef LELY_UTIL_TIME_INLINE 30 #define LELY_UTIL_TIME_INLINE static inline 39 struct timespec *tp,
const struct timespec *inc);
43 struct timespec *tp, uint_least64_t sec);
47 struct timespec *tp, uint_least64_t msec);
51 struct timespec *tp, uint_least64_t usec);
55 struct timespec *tp, uint_least64_t nsec);
59 struct timespec *tp,
const struct timespec *dec);
63 struct timespec *tp, uint_least64_t sec);
67 struct timespec *tp, uint_least64_t msec);
71 struct timespec *tp, uint_least64_t usec);
75 struct timespec *tp, uint_least64_t nsec);
79 const struct timespec *t1,
const struct timespec *t2);
86 const struct timespec *t1,
const struct timespec *t2);
93 const struct timespec *t1,
const struct timespec *t2);
100 const struct timespec *t1,
const struct timespec *t2);
109 LELY_UTIL_TIME_INLINE
int timespec_cmp(
const void *p1,
const void *p2);
114 tp->tv_sec += inc->tv_sec;
115 tp->tv_nsec += inc->tv_nsec;
117 if (tp->tv_nsec >= 1000000000l) {
119 tp->tv_nsec -= 1000000000l;
132 struct timespec inc = { (time_t)(msec / 1000),
133 (long)((msec % 1000) * 1000000l) };
140 struct timespec inc = { (time_t)(usec / 1000000l),
141 (long)((usec % 1000000l) * 1000) };
148 struct timespec inc = { (time_t)(nsec / 1000000000l),
149 (long)(nsec % 1000000000l) };
156 tp->tv_sec -= dec->tv_sec;
157 tp->tv_nsec -= dec->tv_nsec;
159 if (tp->tv_nsec < 0) {
161 tp->tv_nsec += 1000000000l;
174 struct timespec dec = { (time_t)(msec / 1000),
175 (long)((msec % 1000) * 1000000l) };
182 struct timespec dec = { (time_t)(usec / 1000000l),
183 (long)((usec % 1000000l) * 1000) };
190 struct timespec dec = { (time_t)(nsec / 1000000000l),
191 (long)(nsec % 1000000000l) };
198 return (t1->tv_sec - t2->tv_sec)
199 + (t1->tv_nsec - t2->tv_nsec) / 1000000000l;
205 return (int_least64_t)(t1->tv_sec - t2->tv_sec) * 1000
206 + (t1->tv_nsec - t2->tv_nsec) / 1000000l;
212 return (int_least64_t)(t1->tv_sec - t2->tv_sec) * 1000000l
213 + (t1->tv_nsec - t2->tv_nsec) / 1000;
219 return (int_least64_t)(t1->tv_sec - t2->tv_sec) * 1000000000l
220 + t1->tv_nsec - t2->tv_nsec;
234 const struct timespec *t1 = (
const struct timespec *)p1;
235 const struct timespec *t2 = (
const struct timespec *)p2;
237 int cmp = (t2->tv_sec < t1->tv_sec) - (t1->tv_sec < t2->tv_sec);
239 cmp = (t2->tv_nsec < t1->tv_nsec) - (t1->tv_nsec < t2->tv_nsec);
247 #endif // !LELY_UTIL_TIME_H_ void timespec_sub_sec(struct timespec *tp, uint_least64_t sec)
Subtracts sec seconds to the time at tp.
void timespec_sub_msec(struct timespec *tp, uint_least64_t msec)
Subtracts msec milliseconds to the time at tp.
void timespec_add_usec(struct timespec *tp, uint_least64_t usec)
Adds usec microseconds to the time at tp.
void timespec_add(struct timespec *tp, const struct timespec *inc)
Adds the time interval *inc to the time at tp.
int_least64_t timespec_diff_nsec(const struct timespec *t1, const struct timespec *t2)
Returns the time difference (in nanoseconds) between *t1 and *t2.
int timespec_cmp(const void *p1, const void *p2)
Compares two times.
This header file is part of the C11 and POSIX compatibility library; it includes <stdint.h> and defines any missing functionality.
int_least64_t timespec_diff_msec(const struct timespec *t1, const struct timespec *t2)
Returns the time difference (in milliseconds) between *t1 and *t2.
int_least64_t timespec_diff_usec(const struct timespec *t1, const struct timespec *t2)
Returns the time difference (in microseconds) between *t1 and *t2.
int_least64_t timespec_diff_sec(const struct timespec *t1, const struct timespec *t2)
Returns the time difference (in seconds) between *t1 and *t2.
void timespec_sub_nsec(struct timespec *tp, uint_least64_t nsec)
Subtracts nsec nanoseconds to the time at tp.
void timespec_add_msec(struct timespec *tp, uint_least64_t msec)
Adds msec milliseconds to the time at tp.
void timespec_sub_usec(struct timespec *tp, uint_least64_t usec)
Subtracts usec microseconds to the time at tp.
void timespec_add_sec(struct timespec *tp, uint_least64_t sec)
Adds sec seconds to the time at tp.
void timespec_add_nsec(struct timespec *tp, uint_least64_t nsec)
Adds nsec nanoseconds to the time at tp.
This header file is part of the C11 and POSIX compatibility library; it includes <time.h> and defines any missing functionality.
void timespec_sub(struct timespec *tp, const struct timespec *dec)
Subtracts the time interval *inc to the time at tp.