diff options
Diffstat (limited to 'libudev/libudev-util.c')
-rw-r--r-- | libudev/libudev-util.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libudev/libudev-util.c b/libudev/libudev-util.c index 6c309afd05..51dd017467 100644 --- a/libudev/libudev-util.c +++ b/libudev/libudev-util.c @@ -18,6 +18,7 @@ #include <dirent.h> #include <ctype.h> #include <fcntl.h> +#include <time.h> #include <sys/stat.h> #include "libudev.h" @@ -553,3 +554,15 @@ uint64_t util_string_bloom64(const char *str) bits |= 1LLU << ((hash >> 18) & 63); return bits; } + +#define USEC_PER_SEC 1000000ULL +#define NSEC_PER_USEC 1000ULL +unsigned long long usec_monotonic(void) +{ + struct timespec ts; + + if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) + return 0; + return (unsigned long long) ts.tv_sec * USEC_PER_SEC + + (unsigned long long) ts.tv_nsec / NSEC_PER_USEC; +} |