X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fbasic%2Ftime-util.c;h=6c8973ce31e5fa63669a88cfb53a533b489d695a;hp=e849ccc57d96841cc3822eeb6293630be941a55b;hb=903ff64069e63a831ad1036182d4e56421e0dc86;hpb=5db0e7adf018c82dd63cd21d31dd313dff5561af diff --git a/src/basic/time-util.c b/src/basic/time-util.c index e849ccc57..6c8973ce3 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -91,6 +91,32 @@ dual_timestamp* dual_timestamp_from_monotonic(dual_timestamp *ts, usec_t u) { } #endif // 0 +dual_timestamp* dual_timestamp_from_boottime_or_monotonic(dual_timestamp *ts, usec_t u) { + int64_t delta; + + if (u == USEC_INFINITY) { + ts->realtime = ts->monotonic = USEC_INFINITY; + return ts; + } + ts->realtime = now(CLOCK_REALTIME); + ts->monotonic = now(CLOCK_MONOTONIC); + + delta = (int64_t) now(clock_boottime_or_monotonic()) - (int64_t) u; + + if ((int64_t) ts->realtime > delta) + ts->realtime -= delta; + else + ts->realtime = 0; + + if ((int64_t) ts->monotonic > delta) + ts->monotonic -= delta; + else + ts->monotonic = 0; + + return ts; +} + + usec_t timespec_load(const struct timespec *ts) { assert(ts); @@ -991,6 +1017,7 @@ bool timezone_is_valid(const char *name) { return true; } +#endif // 0 clockid_t clock_boottime_or_monotonic(void) { static clockid_t clock = -1; @@ -1009,4 +1036,3 @@ clockid_t clock_boottime_or_monotonic(void) { return clock; } -#endif // 0