From 93dfcf74cb5fccae3da07897d8613ae6cab958a0 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 1 Apr 2019 14:06:28 -0700 Subject: Export of internal Abseil changes. -- 855576faf9556573fd74c2874b290d8feb6565d5 by Gennadiy Rozental : Import of CCTZ from GitHub. PiperOrigin-RevId: 241395451 -- b93bfd43eb2a992258f131e10f503526cfec6d48 by CJ Johnson : Fixes comment over AbslHashValue for InlinedVector PiperOrigin-RevId: 241368320 -- 75f58dafcac7d78c28d92a61ec7e53c5b3b86697 by Matt Kulukundis : Do not call sampling logic for tables with custom allocators. PiperOrigin-RevId: 241356451 -- 09f1b4889476ff707a54189aff540e2fe1edcf61 by Derek Mauro : Re-enable optionalTest.InPlaceTSFINAEBug after libc++ update PiperOrigin-RevId: 241222673 -- 01a8bb5a8cb1e13e88ddb92f9c0160beb6e126be by Derek Mauro : Update Clang on Kokoro to r356196. This includes a workaround for a -Wgnu-include-next warning fixed by https://reviews.llvm.org/rG0706e144d57305782988dd4367530ae04986116f PiperOrigin-RevId: 241222395 -- 1de66bb669a7ec1494d6064677687f761ee2d369 by Abseil Team : Remove identical test and fix char to string per comment PiperOrigin-RevId: 240855512 GitOrigin-RevId: 855576faf9556573fd74c2874b290d8feb6565d5 Change-Id: Ie155b209ef5567e6597da6ef1844db7e2ad72586 --- absl/time/internal/cctz/src/time_zone_lookup.cc | 33 +++++++++++++++---------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'absl/time/internal/cctz/src/time_zone_lookup.cc') diff --git a/absl/time/internal/cctz/src/time_zone_lookup.cc b/absl/time/internal/cctz/src/time_zone_lookup.cc index fd04e2df3985..a27bfc1353a3 100644 --- a/absl/time/internal/cctz/src/time_zone_lookup.cc +++ b/absl/time/internal/cctz/src/time_zone_lookup.cc @@ -23,6 +23,7 @@ #if defined(__APPLE__) #include +#include #endif #include @@ -121,24 +122,32 @@ time_zone fixed_time_zone(const seconds& offset) { time_zone local_time_zone() { const char* zone = ":localtime"; +#if defined(__ANDROID__) + char sysprop[PROP_VALUE_MAX]; + if (__system_property_get("persist.sys.timezone", sysprop) > 0) { + zone = sysprop; + } +#endif +#if defined(__APPLE__) + std::vector buffer; + CFTimeZoneRef tz_default = CFTimeZoneCopyDefault(); + if (CFStringRef tz_name = CFTimeZoneGetName(tz_default)) { + CFStringEncoding encoding = kCFStringEncodingUTF8; + CFIndex length = CFStringGetLength(tz_name); + buffer.resize(CFStringGetMaximumSizeForEncoding(length, encoding) + 1); + if (CFStringGetCString(tz_name, &buffer[0], buffer.size(), encoding)) { + zone = &buffer[0]; + } + } + CFRelease(tz_default); +#endif // Allow ${TZ} to override to default zone. char* tz_env = nullptr; #if defined(_MSC_VER) _dupenv_s(&tz_env, nullptr, "TZ"); -#elif defined(__APPLE__) - CFTimeZoneRef system_time_zone = CFTimeZoneCopyDefault(); - CFStringRef tz_name = CFTimeZoneGetName(system_time_zone); - tz_env = strdup(CFStringGetCStringPtr(tz_name, CFStringGetSystemEncoding())); - CFRelease(system_time_zone); #else tz_env = std::getenv("TZ"); -#endif -#if defined(__ANDROID__) - char sysprop[PROP_VALUE_MAX]; - if (tz_env == nullptr) - if (__system_property_get("persist.sys.timezone", sysprop) > 0) - tz_env = sysprop; #endif if (tz_env) zone = tz_env; @@ -163,8 +172,6 @@ time_zone local_time_zone() { #if defined(_MSC_VER) free(localtime_env); free(tz_env); -#elif defined(__APPLE__) - free(tz_env); #endif time_zone tz; -- cgit 1.4.1