From: Lucas De Marchi Date: Sat, 31 Dec 2011 14:28:54 +0000 (-0200) Subject: util: add helper function to compare timestamps X-Git-Tag: v3~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b29ef6f59ddc0d0aebac2e8a39fdbe78f68512a;p=thirdparty%2Fkmod.git util: add helper function to compare timestamps --- diff --git a/libkmod/libkmod-util.c b/libkmod/libkmod-util.c index d402cdda..a86eda39 100644 --- a/libkmod/libkmod-util.c +++ b/libkmod/libkmod-util.c @@ -319,3 +319,11 @@ char *path_make_absolute_cwd(const char *p) return r; } + +#define USEC_PER_SEC 1000000ULL +#define NSEC_PER_USEC 1000ULL +unsigned long long ts_usec(const struct timespec *ts) +{ + return (unsigned long long) ts->tv_sec * USEC_PER_SEC + + (unsigned long long) ts->tv_nsec / NSEC_PER_USEC; +} diff --git a/libkmod/libkmod-util.h b/libkmod/libkmod-util.h index a4267151..3cd352c8 100644 --- a/libkmod/libkmod-util.h +++ b/libkmod/libkmod-util.h @@ -23,5 +23,6 @@ char *path_make_absolute_cwd(const char *p) __must_check __attribute__((nonnull( int alias_normalize(const char *alias, char buf[NAME_MAX], size_t *len) __must_check __attribute__((nonnull(1,2))); char *modname_normalize(const char *modname, char buf[NAME_MAX], size_t *len) __attribute__((nonnull(1, 2))); char *path_to_modname(const char *path, char buf[NAME_MAX], size_t *len) __attribute__((nonnull(2))); +unsigned long long ts_usec(const struct timespec *ts); #endif