summaryrefslogtreecommitdiff
path: root/absl/time/internal/get_current_time_posix.inc
diff options
context:
space:
mode:
authorGravatar misterg <misterg@google.com>2017-09-19 16:54:40 -0400
committerGravatar misterg <misterg@google.com>2017-09-19 16:54:40 -0400
commitc2e754829628d1e9b7a16b3389cfdace76950fdf (patch)
tree5a7f056f44e27c30e10025113b644f0b3b5801fc /absl/time/internal/get_current_time_posix.inc
Initial Commit
Diffstat (limited to 'absl/time/internal/get_current_time_posix.inc')
-rw-r--r--absl/time/internal/get_current_time_posix.inc22
1 files changed, 22 insertions, 0 deletions
diff --git a/absl/time/internal/get_current_time_posix.inc b/absl/time/internal/get_current_time_posix.inc
new file mode 100644
index 00000000..65474ca6
--- /dev/null
+++ b/absl/time/internal/get_current_time_posix.inc
@@ -0,0 +1,22 @@
+#include "absl/time/clock.h"
+
+#include <sys/time.h>
+#include <ctime>
+#include <cstdint>
+
+#include "absl/base/internal/raw_logging.h"
+
+namespace absl {
+namespace time_internal {
+
+static int64_t GetCurrentTimeNanosFromSystem() {
+ const int64_t kNanosPerSecond = 1000 * 1000 * 1000;
+ struct timespec ts;
+ ABSL_RAW_CHECK(clock_gettime(CLOCK_REALTIME, &ts) == 0,
+ "Failed to read real-time clock.");
+ return (int64_t{ts.tv_sec} * kNanosPerSecond +
+ int64_t{ts.tv_nsec});
+}
+
+} // namespace time_internal
+} // namespace absl