diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2010-12-15 08:57:46 +0100 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2010-12-15 08:58:46 +0100 |
commit | 9c6a11b1c6c68dabfd28b72d361da0e1930c7321 (patch) | |
tree | 581eed5eeb14013c6ec4e9669ed14d6ed69d107e /libudev/libudev-util.c | |
parent | 93a724d3f8afc4b6fe5c7c9642c79df724324ed3 (diff) |
libudev: record and export "age" of device record
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; +} |