time-util: add timespec_store_nsec()
timespec_store_nsec() is to timespec_store() what timespec_load_nsec() is to timespec_load(), i.e. the nsec version of the usual usec API
This commit is contained in:
+18
-2
@@ -244,12 +244,28 @@ struct timespec *timespec_store(struct timespec *ts, usec_t u) {
|
||||
if (u == USEC_INFINITY ||
|
||||
u / USEC_PER_SEC >= TIME_T_MAX) {
|
||||
ts->tv_sec = (time_t) -1;
|
||||
ts->tv_nsec = (long) -1;
|
||||
ts->tv_nsec = -1L;
|
||||
return ts;
|
||||
}
|
||||
|
||||
ts->tv_sec = (time_t) (u / USEC_PER_SEC);
|
||||
ts->tv_nsec = (long int) ((u % USEC_PER_SEC) * NSEC_PER_USEC);
|
||||
ts->tv_nsec = (long) ((u % USEC_PER_SEC) * NSEC_PER_USEC);
|
||||
|
||||
return ts;
|
||||
}
|
||||
|
||||
struct timespec *timespec_store_nsec(struct timespec *ts, nsec_t n) {
|
||||
assert(ts);
|
||||
|
||||
if (n == NSEC_INFINITY ||
|
||||
n / NSEC_PER_SEC >= TIME_T_MAX) {
|
||||
ts->tv_sec = (time_t) -1;
|
||||
ts->tv_nsec = -1L;
|
||||
return ts;
|
||||
}
|
||||
|
||||
ts->tv_sec = (time_t) (n / NSEC_PER_SEC);
|
||||
ts->tv_nsec = (long) (n % NSEC_PER_SEC);
|
||||
|
||||
return ts;
|
||||
}
|
||||
|
||||
@@ -112,6 +112,7 @@ usec_t triple_timestamp_by_clock(triple_timestamp *ts, clockid_t clock);
|
||||
usec_t timespec_load(const struct timespec *ts) _pure_;
|
||||
nsec_t timespec_load_nsec(const struct timespec *ts) _pure_;
|
||||
struct timespec *timespec_store(struct timespec *ts, usec_t u);
|
||||
struct timespec *timespec_store_nsec(struct timespec *ts, nsec_t n);
|
||||
|
||||
usec_t timeval_load(const struct timeval *tv) _pure_;
|
||||
struct timeval *timeval_store(struct timeval *tv, usec_t u);
|
||||
|
||||
Reference in New Issue
Block a user