]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: add monotime_to_realtime()
authorDavid Lamparter <equinox@diac24.net>
Wed, 17 Jul 2019 13:26:00 +0000 (15:26 +0200)
committerDavid Lamparter <equinox@diac24.net>
Fri, 30 Aug 2019 17:00:45 +0000 (19:00 +0200)
Signed-off-by: David Lamparter <equinox@diac24.net>
lib/monotime.h

index ca27c45dc61437242634b786940095bdc89283a9..e246f177de3ba4d1ed4d6cc12e6a25cd877e2ccf 100644 (file)
@@ -84,6 +84,20 @@ static inline int64_t monotime_until(const struct timeval *ref,
        return (int64_t)tv.tv_sec * 1000000LL + tv.tv_usec;
 }
 
+static inline time_t monotime_to_realtime(const struct timeval *mono,
+                                         struct timeval *realout)
+{
+       struct timeval delta, real;
+
+       monotime_since(mono, &delta);
+       gettimeofday(&real, NULL);
+
+       timersub(&real, &delta, &real);
+       if (realout)
+               *realout = real;
+       return real.tv_sec;
+}
+
 /* Char buffer size for time-to-string api */
 #define MONOTIME_STRLEN 32