diff options
author | Daniel Mack <github@zonque.org> | 2016-02-02 17:32:31 +0100 |
---|---|---|
committer | Daniel Mack <github@zonque.org> | 2016-02-02 17:32:31 +0100 |
commit | 14ddf4207ffece3b0843bd1250a64c41c32ac9ae (patch) | |
tree | 4f6863c989de0b55f7305464c154011578e72cc6 /src/basic/time-util.h | |
parent | b72190e90f0846956e609075fb9113dba9bc8f0f (diff) | |
parent | 2c29d3324dbcab7720cc6bb5852b1a01daa6772c (diff) |
Merge pull request #2506 from poettering/resolved-and-more
pid 1 fixes, resolved fixes, and more
Diffstat (limited to 'src/basic/time-util.h')
-rw-r--r-- | src/basic/time-util.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/basic/time-util.h b/src/basic/time-util.h index 7321e3c670..b37d5ad5dc 100644 --- a/src/basic/time-util.h +++ b/src/basic/time-util.h @@ -127,3 +127,16 @@ time_t mktime_or_timegm(struct tm *tm, bool utc); struct tm *localtime_or_gmtime_r(const time_t *t, struct tm *tm, bool utc); unsigned long usec_to_jiffies(usec_t usec); + +static inline usec_t usec_add(usec_t a, usec_t b) { + usec_t c; + + /* Adds two time values, and makes sure USEC_INFINITY as input results as USEC_INFINITY in output, and doesn't + * overflow. */ + + c = a + b; + if (c < a || c < b) /* overflow check */ + return USEC_INFINITY; + + return c; +} |