diff options
Diffstat (limited to 'winpr/libwinpr/timezone/timezone.c')
-rw-r--r-- | winpr/libwinpr/timezone/timezone.c | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/winpr/libwinpr/timezone/timezone.c b/winpr/libwinpr/timezone/timezone.c index 6ca3e54..a727d67 100644 --- a/winpr/libwinpr/timezone/timezone.c +++ b/winpr/libwinpr/timezone/timezone.c @@ -23,6 +23,7 @@ #include <winpr/wtypes.h> #include <winpr/timezone.h> #include <winpr/crt.h> +#include <winpr/assert.h> #include <winpr/file.h> #include "../log.h" @@ -308,6 +309,11 @@ static TIME_ZONE_ENTRY* winpr_detect_windows_time_zone(void) free(tzid); tzid = NULL; } + else if (tzid[0] == ':') + { + /* Remove leading colon, see tzset(3) */ + memmove(tzid, tzid + 1, nSize - sizeof(char)); + } } if (tzid == NULL) @@ -323,7 +329,14 @@ static TIME_ZONE_ENTRY* winpr_detect_windows_time_zone(void) char buf[1024] = { 0 }; const char* links[] = { buf }; - snprintf(buf, ARRAYSIZE(buf), "%s%s", zipath, tzid); + if (tzid[0] == '/') + { + /* Full path given in TZ */ + links[0] = tzid; + } + else + snprintf(buf, ARRAYSIZE(buf), "%s%s", zipath, tzid); + ntzid = winpr_get_timezone_from_link(links, 1); if (ntzid != NULL) { @@ -390,17 +403,20 @@ winpr_get_current_time_zone_rule(const TIME_ZONE_RULE_ENTRY* rules, UINT32 count DWORD GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation) { time_t t = 0; - struct tm tres; - struct tm* local_time = NULL; + struct tm tres = { 0 }; TIME_ZONE_ENTRY* dtz = NULL; + const TIME_ZONE_INFORMATION empty = { 0 }; LPTIME_ZONE_INFORMATION tz = lpTimeZoneInformation; - lpTimeZoneInformation->StandardBias = 0; - time(&t); - local_time = localtime_r(&t, &tres); + + WINPR_ASSERT(tz); + + *tz = empty; + + t = time(NULL); + struct tm* local_time = localtime_r(&t, &tres); if (!local_time) goto out_error; - memset(tz, 0, sizeof(TIME_ZONE_INFORMATION)); #ifdef WINPR_HAVE_TM_GMTOFF { long bias = -(local_time->tm_gmtoff / 60L); @@ -410,19 +426,14 @@ DWORD GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation) tz->Bias = (LONG)bias; } -#else - tz->Bias = 0; #endif dtz = winpr_detect_windows_time_zone(); if (dtz != NULL) { - const TIME_ZONE_INFORMATION empty = { 0 }; - WLog_DBG(TAG, "tz: Bias=%" PRId32 " sn='%s' dln='%s'", dtz->Bias, dtz->StandardName, dtz->DaylightName); - *tz = empty; tz->Bias = dtz->Bias; if (ConvertUtf8ToWChar(dtz->StandardName, tz->StandardName, ARRAYSIZE(tz->StandardName)) < @@ -462,8 +473,9 @@ DWORD GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation) WLog_DBG(TAG, "tz not found, using computed bias %" PRId32 ".", tz->Bias); out_error: free(dtz); - memcpy(tz->StandardName, L"Client Local Time", sizeof(tz->StandardName)); - memcpy(tz->DaylightName, L"Client Local Time", sizeof(tz->DaylightName)); + if (ConvertUtf8ToWChar("Client Local Time", tz->StandardName, ARRAYSIZE(tz->StandardName)) <= 0) + WLog_WARN(TAG, "Failed to set default timezone name"); + memcpy(tz->DaylightName, tz->StandardName, sizeof(tz->DaylightName)); return 0; /* TIME_ZONE_ID_UNKNOWN */ } |