Commit 3a152643 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot 1

Add timeradd and timersub to the sys/time.h portability header

Summary: I missed these in my initial diff.

Reviewed By: yfeldblum

Differential Revision: D2989977

fb-gh-sync-id: 0efb92286a8aed91ec1d394572cd709e5b6b37ab
shipit-source-id: 0efb92286a8aed91ec1d394572cd709e5b6b37ab
parent d2f85c15
...@@ -20,7 +20,8 @@ ...@@ -20,7 +20,8 @@
#include <cstdint> #include <cstdint>
#include <Windows.h> #include <Windows.h>
extern "C" int gettimeofday(timeval* tv, timezone*) { extern "C" {
int gettimeofday(timeval* tv, timezone*) {
constexpr auto posixWinFtOffset = 116444736000000000ULL; constexpr auto posixWinFtOffset = 116444736000000000ULL;
if (tv) { if (tv) {
...@@ -33,4 +34,23 @@ extern "C" int gettimeofday(timeval* tv, timezone*) { ...@@ -33,4 +34,23 @@ extern "C" int gettimeofday(timeval* tv, timezone*) {
return 0; return 0;
} }
void timeradd(timeval* a, timeval* b, timeval* res) {
res->tv_sec = a->tv_sec + b->tv_sec;
res->tv_usec = a->tv_usec + b->tv_usec;
if (res->tv_usec >= 1000000) {
res->tv_sec++;
res->tv_usec -= 1000000;
}
}
void timersub(timeval* a, timeval* b, timeval* res) {
res->tv_sec = a->tv_sec - b->tv_sec;
res->tv_usec = a->tv_usec - b->tv_usec;
if (res->tv_usec < 0) {
res->tv_sec--;
res->tv_usec += 1000000;
}
}
}
#endif #endif
...@@ -26,5 +26,9 @@ struct timezone { ...@@ -26,5 +26,9 @@ struct timezone {
int tz_dsttime; int tz_dsttime;
}; };
extern "C" int gettimeofday(timeval* tv, timezone*); extern "C" {
int gettimeofday(timeval* tv, timezone*);
void timeradd(timeval* a, timeval* b, timeval* res);
void timersub(timeval* a, timeval* b, timeval* res);
}
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment