diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2014-08-14 11:28:47 -0400 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2014-08-14 11:28:47 -0400 |
commit | 28744043fbaca39dfc9fd1666a8557fd6d8a690f (patch) | |
tree | f0cf30fe98f3e7e535be23c3954973ef02c58e49 /src/shared/time-util.c | |
parent | 819fb6029dde2af3acf23b0fa25c1851b26ce102 (diff) |
src/shared: import many code cleanups from upstream
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/shared/time-util.c')
-rw-r--r-- | src/shared/time-util.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/shared/time-util.c b/src/shared/time-util.c index 6f76e8c19b..3df35b8e24 100644 --- a/src/shared/time-util.c +++ b/src/shared/time-util.c @@ -48,6 +48,34 @@ usec_t timespec_load(const struct timespec *ts) { (usec_t) ts->tv_nsec / NSEC_PER_USEC; } +struct timespec *timespec_store(struct timespec *ts, usec_t u) { + assert(ts); + + if (u == USEC_INFINITY) { + ts->tv_sec = (time_t) -1; + ts->tv_nsec = (long) -1; + return ts; + } + + ts->tv_sec = (time_t) (u / USEC_PER_SEC); + ts->tv_nsec = (long int) ((u % USEC_PER_SEC) * NSEC_PER_USEC); + + return ts; +} +struct timeval *timeval_store(struct timeval *tv, usec_t u) { + assert(tv); + + if (u == USEC_INFINITY) { + tv->tv_sec = (time_t) -1; + tv->tv_usec = (suseconds_t) -1; + } else { + tv->tv_sec = (time_t) (u / USEC_PER_SEC); + tv->tv_usec = (suseconds_t) (u % USEC_PER_SEC); + } + + return tv; +} + char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) { static const struct { const char *suffix; |