AK: Add timeval_to_timespec and timespec_to_timeval conversion methods

Add the ability to easily convert between timeval and timespec.
This commit is contained in:
Brian Gianforcaro 2020-04-26 02:20:26 -07:00 committed by Andreas Kling
parent 089022e7f6
commit 1a80aa999a
Notes: sideshowbarker 2024-07-19 07:16:04 +09:00

View file

@ -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;