From aae50f8a7e7103be8ea9618edd470e797e4333d6 Mon Sep 17 00:00:00 2001 From: Danny Browning Date: Sat, 13 Jan 2018 07:45:25 -0700 Subject: [PATCH] util-time: Add function to convert timespec to epoch millis --- src/util-time.c | 5 +++++ src/util-time.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/util-time.c b/src/util-time.c index 12d174f0f6..ce226fca2d 100644 --- a/src/util-time.c +++ b/src/util-time.c @@ -593,3 +593,8 @@ uint64_t SCGetSecondsUntil (const char *str, time_t epoch) return seconds; } + +uint64_t SCTimespecAsEpochMillis(const struct timespec* ts) +{ + return ts->tv_sec * 1000L + ts->tv_nsec / 1000000L; +} diff --git a/src/util-time.h b/src/util-time.h index 4b2c82e176..00c254b97b 100644 --- a/src/util-time.h +++ b/src/util-time.h @@ -62,6 +62,6 @@ int SCTimeToStringPattern (time_t epoch, const char *pattern, char *str, size_t size); uint64_t SCParseTimeSizeString (const char *str); uint64_t SCGetSecondsUntil (const char *str, time_t epoch); - +uint64_t SCTimespecAsEpochMillis(const struct timespec *ts); #endif /* __UTIL_TIME_H__ */ -- 2.47.2