mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:07:45 +00:00
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:
parent
089022e7f6
commit
1a80aa999a
1 changed files with 16 additions and 0 deletions
16
AK/Time.h
16
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_add;
|
||||||
using AK::timeval_sub;
|
using AK::timeval_sub;
|
||||||
|
using AK::timeval_to_timespec;
|
||||||
|
using AK::timespec_to_timeval;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue