22#ifndef LELY_UTIL_TIME_H_
23#define LELY_UTIL_TIME_H_
30#ifndef LELY_UTIL_TIME_INLINE
31#define LELY_UTIL_TIME_INLINE static inline
44 struct timespec *tp, uint_least64_t sec);
48 struct timespec *tp, uint_least64_t msec);
52 struct timespec *tp, uint_least64_t usec);
56 struct timespec *tp, uint_least64_t nsec);
64 struct timespec *tp, uint_least64_t sec);
68 struct timespec *tp, uint_least64_t msec);
72 struct timespec *tp, uint_least64_t usec);
76 struct timespec *tp, uint_least64_t nsec);
115LELY_UTIL_TIME_INLINE
int timespec_cmp(
const void *p1,
const void *p2);
117LELY_UTIL_TIME_INLINE
void
126 if (tp->
tv_nsec >= 1000000000l) {
132LELY_UTIL_TIME_INLINE
void
140LELY_UTIL_TIME_INLINE
void
143 struct timespec inc = { (time_t)(msec / 1000),
144 (long)((msec % 1000) * 1000000l) };
148LELY_UTIL_TIME_INLINE
void
151 struct timespec inc = { (time_t)(usec / 1000000l),
152 (long)((usec % 1000000l) * 1000) };
156LELY_UTIL_TIME_INLINE
void
159 struct timespec inc = { (time_t)(nsec / 1000000000l),
160 (long)(nsec % 1000000000l) };
164LELY_UTIL_TIME_INLINE
void
179LELY_UTIL_TIME_INLINE
void
187LELY_UTIL_TIME_INLINE
void
190 struct timespec dec = { (time_t)(msec / 1000),
191 (long)((msec % 1000) * 1000000l) };
195LELY_UTIL_TIME_INLINE
void
198 struct timespec dec = { (time_t)(usec / 1000000l),
199 (long)((usec % 1000000l) * 1000) };
203LELY_UTIL_TIME_INLINE
void
206 struct timespec dec = { (time_t)(nsec / 1000000000l),
207 (long)(nsec % 1000000000l) };
211LELY_UTIL_TIME_INLINE int_least64_t
220LELY_UTIL_TIME_INLINE int_least64_t
230LELY_UTIL_TIME_INLINE int_least64_t
236 return (int_least64_t)(t1->
tv_sec - t2->
tv_sec) * 1000000l
240LELY_UTIL_TIME_INLINE int_least64_t
246 return (int_least64_t)(t1->
tv_sec - t2->
tv_sec) * 1000000000l
250LELY_UTIL_TIME_INLINE
int
This header file is part of the C11 and POSIX compatibility library; it includes <time....
This header file is part of the C11 and POSIX compatibility library; it includes <stdint....
A time type with nanosecond resolution.
long tv_nsec
Nanoseconds [0, 999999999].
time_t tv_sec
Whole seconds (>= 0).
int timespec_cmp(const void *p1, const void *p2)
Compares two times.
void timespec_sub_msec(struct timespec *tp, uint_least64_t msec)
Subtracts msec milliseconds from 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(struct timespec *tp, const struct timespec *inc)
Adds the time interval *inc 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_sub(struct timespec *tp, const struct timespec *dec)
Subtracts the time interval *dec from the time at tp.
void timespec_sub_nsec(struct timespec *tp, uint_least64_t nsec)
Subtracts nsec nanoseconds from the time at tp.
void timespec_add_msec(struct timespec *tp, uint_least64_t msec)
Adds msec milliseconds to the time at tp.
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_usec(struct timespec *tp, uint_least64_t usec)
Subtracts usec microseconds from the time at tp.
int_least64_t timespec_diff_msec(const struct timespec *t1, const struct timespec *t2)
Returns the time difference (in milliseconds) between *t1 and *t2.
void timespec_sub_sec(struct timespec *tp, uint_least64_t sec)
Subtracts sec seconds from 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.
void timespec_add_nsec(struct timespec *tp, uint_least64_t nsec)
Adds nsec nanoseconds to the time at tp.
int_least64_t timespec_diff_usec(const struct timespec *t1, const struct timespec *t2)
Returns the time difference (in microseconds) between *t1 and *t2.