1
0
mirror of https://github.com/anope/anope.git synced 2026-06-25 03:56:40 +02:00

Use clock_gettime if it is available.

This commit is contained in:
Sadie Powell
2024-03-18 11:13:46 +00:00
parent 753119c4a1
commit cb3848b7db
13 changed files with 42 additions and 31 deletions
+23
View File
@@ -785,3 +785,26 @@ size_t Anope::Distance(const Anope::string &s1, const Anope::string &s2)
}
return costs[s2.length()];
}
void Anope::UpdateTime()
{
#ifdef _WIN32
SYSTEMTIME st;
GetSystemTime(&st);
CurTime = time(nullptr);
CurTimeNs = st.wMilliseconds;
#elif HAVE_CLOCK_GETTIME
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
CurTime = ts.tv_sec;
CurTimeNs = ts.tv_nsec;
#else
struct timeval tv;
gettimeofday(&tv, nullptr);
CurTime = tv.tv_sec;
CurTimeNs = tv.tv_usec * 1000;
#endif
}