diff options
author | 2021-01-22 10:40:16 +0900 | |
---|---|---|
committer | 2021-01-22 12:30:44 +0000 | |
commit | ef01e763eb700b513e4042ef7a1fbd22ecb10fc4 (patch) | |
tree | e25f0ae7bb2c36a83159ca4b649296b381caea56 /libartbase/base/time_utils.cc | |
parent | 7968cae11af60796b27398a95c32ff0cc31457a4 (diff) |
Guard clock_gettime
clock_gettime is available on mac os starting from 10.12. On older
versions, let's use time(2).
Bug: 178124881
Test: watch a forrest run on mac
Change-Id: I60699cc013f090fe131642bf90afcfd3c6e9bdc6
Diffstat (limited to 'libartbase/base/time_utils.cc')
-rw-r--r-- | libartbase/base/time_utils.cc | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/libartbase/base/time_utils.cc b/libartbase/base/time_utils.cc index 037d7b59a3..aeb7fa21a5 100644 --- a/libartbase/base/time_utils.cc +++ b/libartbase/base/time_utils.cc @@ -136,19 +136,24 @@ std::string GetIsoDate() { #ifdef _WIN32 time_t now = time(nullptr); localtime_s(&tmbuf, &now); - tm* ptm = &tmbuf; ns = 0; #else - timespec now; - clock_gettime(CLOCK_REALTIME, &now); - tm* ptm = localtime_r(&now.tv_sec, &tmbuf); - ns = now.tv_nsec; + if (__builtin_available(macOS 10.12, *)) { + timespec now; + clock_gettime(CLOCK_REALTIME, &now); + localtime_r(&now.tv_sec, &tmbuf); + ns = now.tv_nsec; + } else { + time_t now = time(nullptr); + localtime_r(&now, &tmbuf); + ns = 0; + } #endif char zone[16] = {}; - strftime(zone, sizeof(zone), "%z", ptm); + strftime(zone, sizeof(zone), "%z", &tmbuf); return StringPrintf("%04d-%02d-%02d %02d:%02d:%02d.%09d%s", - ptm->tm_year + 1900, ptm->tm_mon+1, ptm->tm_mday, - ptm->tm_hour, ptm->tm_min, ptm->tm_sec, ns, zone); + tmbuf.tm_year + 1900, tmbuf.tm_mon+1, tmbuf.tm_mday, + tmbuf.tm_hour, tmbuf.tm_min, tmbuf.tm_sec, ns, zone); } uint64_t MilliTime() { |