Add timeradd and timersub to the sys/time.h portability header
authorChristopher Dykes <cdykes@fb.com>
Tue, 1 Mar 2016 17:59:36 +0000 (09:59 -0800)
committerFacebook Github Bot 1 <facebook-github-bot-1-bot@fb.com>
Tue, 1 Mar 2016 18:05:32 +0000 (10:05 -0800)
Summary: I missed these in my initial diff.

Reviewed By: yfeldblum

Differential Revision: D2989977

fb-gh-sync-id: 0efb92286a8aed91ec1d394572cd709e5b6b37ab
shipit-source-id: 0efb92286a8aed91ec1d394572cd709e5b6b37ab

folly/portability/SysTime.cpp
folly/portability/SysTime.h

index 9b46b71174bcfd6adb42895c2f839d8ddf224880..9969a171440242defa9a3487b4262b3763711dbd 100755 (executable)
@@ -20,7 +20,8 @@
 #include <cstdint>
 #include <Windows.h>
 
-extern "C" int gettimeofday(timeval* tv, timezone*) {
+extern "C" {
+int gettimeofday(timeval* tv, timezone*) {
   constexpr auto posixWinFtOffset = 116444736000000000ULL;
 
   if (tv) {
@@ -33,4 +34,23 @@ extern "C" int gettimeofday(timeval* tv, timezone*) {
 
   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
index 56b572f27653d827dbbd3a51091bafd738c8394c..162ff21ac132b82e7ecd918a6faeebdde1fa8f8b 100755 (executable)
@@ -26,5 +26,9 @@ struct timezone {
   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