diff options
author | Brian Gianforcaro <b.gianfo@gmail.com> | 2020-04-26 02:20:26 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-26 21:31:52 +0200 |
commit | 1a80aa999ab6ac3748781c0f65078e19c5920698 (patch) | |
tree | 488b854b55ae89ab69072aee837399a97f982f4d /AK/Time.h | |
parent | 089022e7f6dbc38583be3321a7a20de1f4999a12 (diff) | |
download | serenity-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.h | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -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; |