summaryrefslogtreecommitdiff
path: root/AK/Time.h
diff options
context:
space:
mode:
authorBrian Gianforcaro <b.gianfo@gmail.com>2020-04-26 02:20:26 -0700
committerAndreas Kling <kling@serenityos.org>2020-04-26 21:31:52 +0200
commit1a80aa999ab6ac3748781c0f65078e19c5920698 (patch)
tree488b854b55ae89ab69072aee837399a97f982f4d /AK/Time.h
parent089022e7f6dbc38583be3321a7a20de1f4999a12 (diff)
downloadserenity-1a80aa999ab6ac3748781c0f65078e19c5920698.zip
AK: Add timeval_to_timespec and timespec_to_timeval conversion methods
Add the ability to easily convert between timeval and timespec.
Diffstat (limited to 'AK/Time.h')
-rw-r--r--AK/Time.h16
1 files changed, 16 insertions, 0 deletions
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<typename TimevalType, typename TimespecType>
+inline void timeval_to_timespec(const TimevalType& tv, TimespecType& ts)
+{
+ ts.tv_sec = tv.tv_sec;
+ ts.tv_nsec = tv.tv_usec * 1000;
+}
+
+template<typename TimespecType, typename TimevalType>
+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;