From fb3f85779b28ff2d16218dbb393d5c191322a747 Mon Sep 17 00:00:00 2001 From: ddoe Date: Mon, 19 Jul 2021 10:37:49 +0200 Subject: [PATCH] fixup! Improvement: Add a way to get timezone from environment. Firstly get timezone from environment. If not present, use file method --- winpr/libwinpr/timezone/timezone.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/winpr/libwinpr/timezone/timezone.c b/winpr/libwinpr/timezone/timezone.c index 57b64aab5..b99d8f794 100644 --- a/winpr/libwinpr/timezone/timezone.c +++ b/winpr/libwinpr/timezone/timezone.c @@ -21,6 +21,7 @@ #include "config.h" #endif +#include #include #include #include @@ -284,15 +285,21 @@ static TIME_ZONE_ENTRY* winpr_detect_windows_time_zone(void) { size_t i, j; char* tzid = NULL; + LPCSTR tz = "TZ"; - char* tzenv = getenv("TZ"); - if (tzenv) { - tzid = strdup(tzenv); + DWORD nSize = GetEnvironmentVariableA(tz, NULL, 0); + if (nSize) + { + tzid = (char*)malloc(nSize); + if (!GetEnvironmentVariableA(tz, tzid, nSize)) + { + free(tzid); + tzid = NULL; + } } - if (tzid == NULL) { + if (tzid == NULL) tzid = winpr_get_unix_timezone_identifier_from_file(); - } if (tzid == NULL) tzid = winpr_get_timezone_from_link();