From f25a603708aaadbb0dae0e3dce2f3067d48628d5 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Thu, 20 Apr 2017 09:47:24 -0700 Subject: [PATCH] Implement GetLastModificationTime for linux --- src/platform_linux.cc | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/platform_linux.cc b/src/platform_linux.cc index d9969e45..04289b53 100644 --- a/src/platform_linux.cc +++ b/src/platform_linux.cc @@ -21,14 +21,13 @@ #include #include // required for stat.h -#include // no clue why required -- man pages say so +#include + #include /* For O_* constants */ #include /* For mode constants */ #include #include -#include /* For mode constants */ -#include /* For O_* constants */ #ifndef __APPLE__ #include @@ -163,6 +162,26 @@ void SetCurrentThreadName(const std::string& thread_name) { #endif } +int64_t GetLastModificationTime(const std::string& absolute_path) { + struct stat buf; + if (stat(absolute_path.c_str(), &buf) != 0) { + switch (errno) { + case ENOENT: + std::cerr << "GetLastModificationTime: unable to find file " << absolute_path << std::endl; + break; + case EINVAL: + std::cerr << "GetLastModificationTime: invalid param to _stat for file file " << absolute_path << std::endl; + break; + default: + std::cerr << "GetLastModificationTime: unhandled for " << absolute_path << std::endl; + exit(1); + break; + } + } + + return buf.st_mtime; +} + std::vector GetPlatformClangArguments() { // TODO: use install config variable for path? return {