< prev index next >

src/java.base/windows/native/libjava/TimeZone_md.c

Print this page
rev 51713 : [mq]: 8209167

*** 34,43 **** --- 34,44 ---- #define VALUE_MAPID 2 #define VALUE_GMTOFFSET 3 #define MAX_ZONE_CHAR 256 #define MAX_MAPID_LENGTH 32 + #define MAX_REGION_LENGTH 4 #define NT_TZ_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones" #define WIN_TZ_KEY "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Time Zones" #define WIN_CURRENT_TZ_KEY "System\\CurrentControlSet\\Control\\TimeZoneInformation"
*** 143,153 **** } /* * Gets the current time zone entry in the "Time Zones" registry. */ ! static int getWinTimeZone(char *winZoneName, char *winMapID) { DYNAMIC_TIME_ZONE_INFORMATION dtzi; DWORD timeType; DWORD bufSize; DWORD val; --- 144,154 ---- } /* * Gets the current time zone entry in the "Time Zones" registry. */ ! static int getWinTimeZone(char *winZoneName) { DYNAMIC_TIME_ZONE_INFORMATION dtzi; DWORD timeType; DWORD bufSize; DWORD val;
*** 229,239 **** TCHAR subKeyName[MAX_ZONE_CHAR]; TCHAR szValue[MAX_ZONE_CHAR]; WCHAR stdNameInReg[MAX_ZONE_CHAR]; TziValue tempTzi; WCHAR *stdNamePtr = tzi.StandardName; - DWORD valueSize; int onlyMapID; timeType = GetTimeZoneInformation(&tzi); if (timeType == TIME_ZONE_ID_INVALID) { goto err; --- 230,239 ----
*** 370,397 **** } out: (void) RegCloseKey(hSubKey); } - /* - * Get the "MapID" value of the registry to be able to eliminate - * duplicated key names later. - */ - valueSize = MAX_MAPID_LENGTH; - ret = RegQueryValueExA(hSubKey, "MapID", NULL, &valueType, winMapID, &valueSize); - (void) RegCloseKey(hSubKey); (void) RegCloseKey(hKey); - - if (ret != ERROR_SUCCESS) { - /* - * Vista doesn't have mapID. VALUE_UNKNOWN should be returned - * only for Windows NT. - */ - if (onlyMapID == 1) { - return VALUE_UNKNOWN; - } - } } return VALUE_KEY; err: --- 370,380 ----
*** 408,446 **** /* * Index values for the mapping table. */ #define TZ_WIN_NAME 0 ! #define TZ_MAPID 1 ! #define TZ_REGION 2 ! #define TZ_JAVA_NAME 3 ! #define TZ_NITEMS 4 /* number of items (fields) */ /* * Looks up the mapping table (tzmappings) and returns a Java time * zone ID (e.g., "America/Los_Angeles") if found. Otherwise, NULL is * returned. - * - * value_type is one of the following values: - * VALUE_KEY for exact key matching - * VALUE_MAPID for MapID (this is - * required for the old Windows, such as NT 4.0 SP3). */ ! static char *matchJavaTZ(const char *java_home_dir, int value_type, char *tzName, ! char *mapID) { int line; int IDmatched = 0; FILE *fp; char *javaTZName = NULL; char *items[TZ_NITEMS]; char *mapFileName; char lineBuffer[MAX_ZONE_CHAR * 4]; - int noMapID = *mapID == '\0'; /* no mapID on Vista and later */ int offset = 0; const char* errorMessage = "unknown error"; mapFileName = malloc(strlen(java_home_dir) + strlen(MAPPINGS_FILE) + 1); if (mapFileName == NULL) { return NULL; } --- 391,435 ---- /* * Index values for the mapping table. */ #define TZ_WIN_NAME 0 ! #define TZ_REGION 1 ! #define TZ_JAVA_NAME 2 ! #define TZ_NITEMS 3 /* number of items (fields) */ /* * Looks up the mapping table (tzmappings) and returns a Java time * zone ID (e.g., "America/Los_Angeles") if found. Otherwise, NULL is * returned. */ ! static char *matchJavaTZ(const char *java_home_dir, char *tzName) { int line; int IDmatched = 0; FILE *fp; char *javaTZName = NULL; char *items[TZ_NITEMS]; char *mapFileName; char lineBuffer[MAX_ZONE_CHAR * 4]; int offset = 0; const char* errorMessage = "unknown error"; + char region[MAX_REGION_LENGTH]; + + // Get the user's location + if (GetGeoInfo(GetUserGeoID(GEOCLASS_NATION), + GEO_ISO2, region, MAX_REGION_LENGTH, 0) == 0) { + // If GetGeoInfo fails, fallback to LCID's country + LCID lcid = GetUserDefaultLCID(); + if (GetLocaleInfo(lcid, + LOCALE_SISO3166CTRYNAME, region, MAX_REGION_LENGTH) == 0 && + GetLocaleInfo(lcid, + LOCALE_SISO3166CTRYNAME2, region, MAX_REGION_LENGTH) == 0) { + region[0] = '\0'; + } + } mapFileName = malloc(strlen(java_home_dir) + strlen(MAPPINGS_FILE) + 1); if (mapFileName == NULL) { return NULL; }
*** 492,523 **** errorMessage = "illegal non-newline character found"; offset = (int)(idx - lineBuffer); goto illegal_format; } - if (noMapID || strcmp(mapID, items[TZ_MAPID]) == 0) { /* ! * When there's no mapID, we need to scan items until the * exact match is found or the end of data is detected. */ - if (!noMapID) { - IDmatched = 1; - } if (strcmp(items[TZ_WIN_NAME], tzName) == 0) { /* * Found the time zone in the mapping table. */ javaTZName = _strdup(items[TZ_JAVA_NAME]); break; } - } else { - if (IDmatched == 1) { - /* - * No need to look up the mapping table further. - */ - break; - } } } fclose(fp); return javaTZName; --- 481,504 ---- errorMessage = "illegal non-newline character found"; offset = (int)(idx - lineBuffer); goto illegal_format; } /* ! * We need to scan items until the * exact match is found or the end of data is detected. */ if (strcmp(items[TZ_WIN_NAME], tzName) == 0) { /* * Found the time zone in the mapping table. + * Check the region code and select the appropriate entry */ + if (strcmp(items[TZ_REGION], region) == 0 || + strcmp(items[TZ_REGION], "001") == 0) { javaTZName = _strdup(items[TZ_JAVA_NAME]); break; } } } fclose(fp); return javaTZName;
*** 533,555 **** * Detects the platform time zone which maps to a Java time zone ID. */ char *findJavaTZ_md(const char *java_home_dir) { char winZoneName[MAX_ZONE_CHAR]; - char winMapID[MAX_MAPID_LENGTH]; char *std_timezone = NULL; int result; ! winMapID[0] = 0; ! result = getWinTimeZone(winZoneName, winMapID); if (result != VALUE_UNKNOWN) { if (result == VALUE_GMTOFFSET) { std_timezone = _strdup(winZoneName); } else { ! std_timezone = matchJavaTZ(java_home_dir, result, ! winZoneName, winMapID); if (std_timezone == NULL) { std_timezone = getGMTOffsetID(); } } } --- 514,533 ---- * Detects the platform time zone which maps to a Java time zone ID. */ char *findJavaTZ_md(const char *java_home_dir) { char winZoneName[MAX_ZONE_CHAR]; char *std_timezone = NULL; int result; ! result = getWinTimeZone(winZoneName); if (result != VALUE_UNKNOWN) { if (result == VALUE_GMTOFFSET) { std_timezone = _strdup(winZoneName); } else { ! std_timezone = matchJavaTZ(java_home_dir, winZoneName); if (std_timezone == NULL) { std_timezone = getGMTOffsetID(); } } }
< prev index next >