chiark / gitweb /
Prep v225: Added needed udev support and re-enabled some masked cgroup functions.
[elogind.git] / src / basic / time-util.c
index ecca227c74bb718cb2b1fc872200ad23b1b7b626..6c8973ce31e5fa63669a88cfb53a533b489d695a 100644 (file)
@@ -67,6 +67,8 @@ dual_timestamp* dual_timestamp_from_realtime(dual_timestamp *ts, usec_t u) {
         return ts;
 }
 
+/// UNNEEDED by elogind
+#if 0
 dual_timestamp* dual_timestamp_from_monotonic(dual_timestamp *ts, usec_t u) {
         int64_t delta;
         assert(ts);
@@ -87,6 +89,33 @@ dual_timestamp* dual_timestamp_from_monotonic(dual_timestamp *ts, usec_t u) {
 
         return ts;
 }
+#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);
@@ -209,9 +238,12 @@ char *format_timestamp_us(char *buf, size_t l, usec_t t) {
         return format_timestamp_internal_us(buf, l, t, false);
 }
 
+/// UNNEEDED by elogind
+#if 0
 char *format_timestamp_us_utc(char *buf, size_t l, usec_t t) {
         return format_timestamp_internal_us(buf, l, t, true);
 }
+#endif // 0
 
 char *format_timestamp_relative(char *buf, size_t l, usec_t t) {
         const char *s;
@@ -386,6 +418,8 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
         return buf;
 }
 
+/// UNNEEDED by elogind
+#if 0
 void dual_timestamp_serialize(FILE *f, const char *name, dual_timestamp *t) {
 
         assert(f);
@@ -418,8 +452,6 @@ int dual_timestamp_deserialize(const char *value, dual_timestamp *t) {
         return 0;
 }
 
-/// UNNEEDED by elogind
-#if 0
 int parse_timestamp(const char *t, usec_t *usec) {
         static const struct {
                 const char *name;