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;
}
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);