add EXPECT_THROW_RE() and EXPECT_THROW_ERRNO() test macros
[folly.git] / folly / portability / Time.h
old mode 100755 (executable)
new mode 100644 (file)
index 0a35b23..eb6c794
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 #pragma once
 
+#include <stdint.h>
 #include <time.h>
 
+#include <folly/portability/Config.h>
+
+// OSX is a pain. The XCode 8 SDK always declares clock_gettime
+// even if the target OS version doesn't support it, so you get
+// an error at runtime because it can't resolve the symbol. We
+// solve that by pretending we have it here in the header and
+// then enable our implementation on the source side so that
+// gets linked in instead.
+#if __MACH__ &&                                                \
+    (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 || \
+     __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0)
+
+#ifdef FOLLY_HAVE_CLOCK_GETTIME
+#undef FOLLY_HAVE_CLOCK_GETTIME
+#endif
+
+#define FOLLY_HAVE_CLOCK_GETTIME 1
+#define FOLLY_FORCE_CLOCK_GETTIME_DEFINITION 1
+
+#endif
+
+// These aren't generic implementations, so we can only declare them on
+// platforms we support.
+#if !FOLLY_HAVE_CLOCK_GETTIME && (defined(__MACH__) || defined(_WIN32))
+#define CLOCK_REALTIME 0
+#define CLOCK_MONOTONIC 1
+#define CLOCK_PROCESS_CPUTIME_ID 2
+#define CLOCK_THREAD_CPUTIME_ID 3
+
+typedef uint8_t clockid_t;
+extern "C" int clock_gettime(clockid_t clk_id, struct timespec* ts);
+extern "C" int clock_getres(clockid_t clk_id, struct timespec* ts);
+#endif
+
 #ifdef _WIN32
 #define TM_YEAR_BASE (1900)
 
@@ -27,8 +62,9 @@ char* ctime_r(const time_t* t, char* buf);
 tm* gmtime_r(const time_t* t, tm* res);
 tm* localtime_r(const time_t* t, tm* o);
 int nanosleep(const struct timespec* request, struct timespec* remain);
-char* strptime(const char* __restrict buf,
-               const char* __restrict fmt,
-               struct tm* __restrict tm);
+char* strptime(
+    const char* __restrict buf,
+    const char* __restrict fmt,
+    struct tm* __restrict tm);
 }
 #endif