From 1a80aa999ab6ac3748781c0f65078e19c5920698 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Sun, 26 Apr 2020 02:20:26 -0700 Subject: [PATCH] AK: Add timeval_to_timespec and timespec_to_timeval conversion methods Add the ability to easily convert between timeval and timespec. --- AK/Time.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/AK/Time.h b/AK/Time.h index ece523e8a3..7a8245ab87 100644 --- a/AK/Time.h +++ b/AK/Time.h @@ -50,7 +50,23 @@ inline void timeval_add(const TimevalType& a, const TimevalType& b, TimevalType& } } +template +inline void timeval_to_timespec(const TimevalType& tv, TimespecType& ts) +{ + ts.tv_sec = tv.tv_sec; + ts.tv_nsec = tv.tv_usec * 1000; +} + +template +inline void timespec_to_timeval(const TimespecType& ts, TimevalType& tv) +{ + tv.tv_sec = ts.tv_sec; + tv.tv_usec = ts.tv_nsec / 1000; +} + } using AK::timeval_add; using AK::timeval_sub; +using AK::timeval_to_timespec; +using AK::timespec_to_timeval;