author | mbaesken |
Fri, 08 Jun 2018 13:06:08 +0200 | |
changeset 50464 | 102ae98c917c |
parent 47216 | 71c04702a3d5 |
child 51730 | cd0775f67ab0 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
50464
102ae98c917c
8204539: improve error messages in matchJavaTZ [windows]
mbaesken
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
#include <windows.h> |
|
27 |
#include <stdio.h> |
|
28 |
#include <stdlib.h> |
|
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
5506
diff
changeset
|
29 |
#include "jvm.h" |
2 | 30 |
#include "TimeZone_md.h" |
31 |
||
32 |
#define VALUE_UNKNOWN 0 |
|
33 |
#define VALUE_KEY 1 |
|
34 |
#define VALUE_MAPID 2 |
|
35 |
#define VALUE_GMTOFFSET 3 |
|
36 |
||
37 |
#define MAX_ZONE_CHAR 256 |
|
38 |
#define MAX_MAPID_LENGTH 32 |
|
39 |
||
40 |
#define NT_TZ_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones" |
|
41 |
#define WIN_TZ_KEY "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Time Zones" |
|
42 |
#define WIN_CURRENT_TZ_KEY "System\\CurrentControlSet\\Control\\TimeZoneInformation" |
|
43 |
||
44 |
typedef struct _TziValue { |
|
45 |
LONG bias; |
|
46 |
LONG stdBias; |
|
47 |
LONG dstBias; |
|
48 |
SYSTEMTIME stdDate; |
|
49 |
SYSTEMTIME dstDate; |
|
50 |
} TziValue; |
|
51 |
||
52 |
/* |
|
53 |
* Registry key names |
|
54 |
*/ |
|
55 |
static void *keyNames[] = { |
|
56 |
(void *) L"StandardName", |
|
57 |
(void *) "StandardName", |
|
58 |
(void *) L"Std", |
|
59 |
(void *) "Std" |
|
60 |
}; |
|
61 |
||
62 |
/* |
|
63 |
* Indices to keyNames[] |
|
64 |
*/ |
|
65 |
#define STANDARD_NAME 0 |
|
66 |
#define STD_NAME 2 |
|
67 |
||
68 |
/* |
|
69 |
* Calls RegQueryValueEx() to get the value for the specified key. If |
|
70 |
* the platform is NT, 2000 or XP, it calls the Unicode |
|
71 |
* version. Otherwise, it calls the ANSI version and converts the |
|
72 |
* value to Unicode. In this case, it assumes that the current ANSI |
|
73 |
* Code Page is the same as the native platform code page (e.g., Code |
|
74 |
* Page 932 for the Japanese Windows systems. |
|
75 |
* |
|
76 |
* `keyIndex' is an index value to the keyNames in Unicode |
|
77 |
* (WCHAR). `keyIndex' + 1 points to its ANSI value. |
|
78 |
* |
|
79 |
* Returns the status value. ERROR_SUCCESS if succeeded, a |
|
80 |
* non-ERROR_SUCCESS value otherwise. |
|
81 |
*/ |
|
82 |
static LONG |
|
83 |
getValueInRegistry(HKEY hKey, |
|
84 |
int keyIndex, |
|
85 |
LPDWORD typePtr, |
|
86 |
LPBYTE buf, |
|
87 |
LPDWORD bufLengthPtr) |
|
88 |
{ |
|
89 |
LONG ret; |
|
90 |
DWORD bufLength = *bufLengthPtr; |
|
91 |
char val[MAX_ZONE_CHAR]; |
|
92 |
DWORD valSize; |
|
93 |
int len; |
|
94 |
||
95 |
*typePtr = 0; |
|
14177 | 96 |
ret = RegQueryValueExW(hKey, (WCHAR *) keyNames[keyIndex], NULL, |
97 |
typePtr, buf, bufLengthPtr); |
|
98 |
if (ret == ERROR_SUCCESS && *typePtr == REG_SZ) { |
|
99 |
return ret; |
|
2 | 100 |
} |
101 |
||
102 |
valSize = sizeof(val); |
|
103 |
ret = RegQueryValueExA(hKey, (char *) keyNames[keyIndex + 1], NULL, |
|
104 |
typePtr, val, &valSize); |
|
105 |
if (ret != ERROR_SUCCESS) { |
|
106 |
return ret; |
|
107 |
} |
|
108 |
if (*typePtr != REG_SZ) { |
|
109 |
return ERROR_BADKEY; |
|
110 |
} |
|
111 |
||
112 |
len = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, |
|
113 |
(LPCSTR) val, -1, |
|
114 |
(LPWSTR) buf, bufLength/sizeof(WCHAR)); |
|
115 |
if (len <= 0) { |
|
116 |
return ERROR_BADKEY; |
|
117 |
} |
|
118 |
return ERROR_SUCCESS; |
|
119 |
} |
|
120 |
||
121 |
/* |
|
122 |
* Produces custom name "GMT+hh:mm" from the given bias in buffer. |
|
123 |
*/ |
|
124 |
static void customZoneName(LONG bias, char *buffer) { |
|
125 |
LONG gmtOffset; |
|
126 |
int sign; |
|
127 |
||
128 |
if (bias > 0) { |
|
129 |
gmtOffset = bias; |
|
130 |
sign = -1; |
|
131 |
} else { |
|
132 |
gmtOffset = -bias; |
|
133 |
sign = 1; |
|
134 |
} |
|
135 |
if (gmtOffset != 0) { |
|
136 |
sprintf(buffer, "GMT%c%02d:%02d", |
|
137 |
((sign >= 0) ? '+' : '-'), |
|
138 |
gmtOffset / 60, |
|
139 |
gmtOffset % 60); |
|
140 |
} else { |
|
141 |
strcpy(buffer, "GMT"); |
|
142 |
} |
|
143 |
} |
|
144 |
||
145 |
/* |
|
146 |
* Gets the current time zone entry in the "Time Zones" registry. |
|
147 |
*/ |
|
148 |
static int getWinTimeZone(char *winZoneName, char *winMapID) |
|
149 |
{ |
|
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
150 |
DYNAMIC_TIME_ZONE_INFORMATION dtzi; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
151 |
DWORD timeType; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
152 |
DWORD bufSize; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
153 |
DWORD val; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
154 |
HANDLE hKey = NULL; |
2 | 155 |
LONG ret; |
156 |
ULONG valueType; |
|
157 |
||
158 |
/* |
|
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
159 |
* Get the dynamic time zone information so that time zone redirection |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
160 |
* can be supported. (see JDK-7044727) |
2 | 161 |
*/ |
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
162 |
timeType = GetDynamicTimeZoneInformation(&dtzi); |
2 | 163 |
if (timeType == TIME_ZONE_ID_INVALID) { |
164 |
goto err; |
|
165 |
} |
|
166 |
||
167 |
/* |
|
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
168 |
* Make sure TimeZoneKeyName is available from the API call. If |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
169 |
* DynamicDaylightTime is disabled, return a custom time zone name |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
170 |
* based on the GMT offset. Otherwise, return the TimeZoneKeyName |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
171 |
* value. |
2 | 172 |
*/ |
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
173 |
if (dtzi.TimeZoneKeyName[0] != 0) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
174 |
if (dtzi.DynamicDaylightTimeDisabled) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
175 |
customZoneName(dtzi.Bias, winZoneName); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
176 |
return VALUE_GMTOFFSET; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
177 |
} |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
178 |
wcstombs(winZoneName, dtzi.TimeZoneKeyName, MAX_ZONE_CHAR); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
179 |
return VALUE_KEY; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
180 |
} |
2 | 181 |
|
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
182 |
/* |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
183 |
* If TimeZoneKeyName is not available, check whether StandardName |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
184 |
* is available to fall back to the older API GetTimeZoneInformation. |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
185 |
* If not, directly read the value from registry keys. |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
186 |
*/ |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
187 |
if (dtzi.StandardName[0] == 0) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
188 |
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_CURRENT_TZ_KEY, 0, |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
189 |
KEY_READ, (PHKEY)&hKey); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
190 |
if (ret != ERROR_SUCCESS) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
191 |
goto err; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
192 |
} |
2 | 193 |
|
194 |
/* |
|
195 |
* Determine if auto-daylight time adjustment is turned off. |
|
196 |
*/ |
|
197 |
bufSize = sizeof(val); |
|
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
198 |
ret = RegQueryValueExA(hKey, "DynamicDaylightTimeDisabled", NULL, |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
199 |
&valueType, (LPBYTE) &val, &bufSize); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
200 |
if (ret != ERROR_SUCCESS) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
201 |
goto err; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
202 |
} |
2 | 203 |
/* |
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
204 |
* Return a custom time zone name if auto-daylight time adjustment |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
205 |
* is disabled. |
2 | 206 |
*/ |
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
207 |
if (val == 1) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
208 |
customZoneName(dtzi.Bias, winZoneName); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
209 |
(void) RegCloseKey(hKey); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
210 |
return VALUE_GMTOFFSET; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
211 |
} |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
212 |
|
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
213 |
bufSize = MAX_ZONE_CHAR; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
214 |
ret = RegQueryValueExA(hKey, "TimeZoneKeyName", NULL, |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
215 |
&valueType, (LPBYTE) winZoneName, &bufSize); |
2 | 216 |
if (ret != ERROR_SUCCESS) { |
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
217 |
goto err; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
218 |
} |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
219 |
(void) RegCloseKey(hKey); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
220 |
return VALUE_KEY; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
221 |
} else { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
222 |
/* |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
223 |
* Fall back to GetTimeZoneInformation |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
224 |
*/ |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
225 |
TIME_ZONE_INFORMATION tzi; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
226 |
HANDLE hSubKey = NULL; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
227 |
DWORD nSubKeys, i; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
228 |
ULONG valueType; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
229 |
TCHAR subKeyName[MAX_ZONE_CHAR]; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
230 |
TCHAR szValue[MAX_ZONE_CHAR]; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
231 |
WCHAR stdNameInReg[MAX_ZONE_CHAR]; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
232 |
TziValue tempTzi; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
233 |
WCHAR *stdNamePtr = tzi.StandardName; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
234 |
DWORD valueSize; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
235 |
int onlyMapID; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
236 |
|
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
237 |
timeType = GetTimeZoneInformation(&tzi); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
238 |
if (timeType == TIME_ZONE_ID_INVALID) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
239 |
goto err; |
2 | 240 |
} |
12849
1e155a915581
7094176: (tz) Incorrect TimeZone display name when DST not applicable / disabled
youdwei
parents:
7668
diff
changeset
|
241 |
|
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
242 |
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_CURRENT_TZ_KEY, 0, |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
243 |
KEY_READ, (PHKEY)&hKey); |
2 | 244 |
if (ret == ERROR_SUCCESS) { |
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
245 |
/* |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
246 |
* Determine if auto-daylight time adjustment is turned off. |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
247 |
*/ |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
248 |
bufSize = sizeof(val); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
249 |
ret = RegQueryValueExA(hKey, "DynamicDaylightTimeDisabled", NULL, |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
250 |
&valueType, (LPBYTE) &val, &bufSize); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
251 |
if (ret == ERROR_SUCCESS) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
252 |
if (val == 1 && tzi.DaylightDate.wMonth != 0) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
253 |
(void) RegCloseKey(hKey); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
254 |
customZoneName(tzi.Bias, winZoneName); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
255 |
return VALUE_GMTOFFSET; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
256 |
} |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
257 |
} |
12849
1e155a915581
7094176: (tz) Incorrect TimeZone display name when DST not applicable / disabled
youdwei
parents:
7668
diff
changeset
|
258 |
|
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
259 |
/* |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
260 |
* Win32 problem: If the length of the standard time name is equal |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
261 |
* to (or probably longer than) 32 in the registry, |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
262 |
* GetTimeZoneInformation() on NT returns a null string as its |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
263 |
* standard time name. We need to work around this problem by |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
264 |
* getting the same information from the TimeZoneInformation |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
265 |
* registry. |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
266 |
*/ |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
267 |
if (tzi.StandardName[0] == 0) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
268 |
bufSize = sizeof(stdNameInReg); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
269 |
ret = getValueInRegistry(hKey, STANDARD_NAME, &valueType, |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
270 |
(LPBYTE) stdNameInReg, &bufSize); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
271 |
if (ret != ERROR_SUCCESS) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
272 |
goto err; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
273 |
} |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
274 |
stdNamePtr = stdNameInReg; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
275 |
} |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
276 |
(void) RegCloseKey(hKey); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
277 |
} |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
278 |
|
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
279 |
/* |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
280 |
* Open the "Time Zones" registry. |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
281 |
*/ |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
282 |
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, NT_TZ_KEY, 0, KEY_READ, (PHKEY)&hKey); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
283 |
if (ret != ERROR_SUCCESS) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
284 |
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_TZ_KEY, 0, KEY_READ, (PHKEY)&hKey); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
285 |
/* |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
286 |
* If both failed, then give up. |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
287 |
*/ |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
288 |
if (ret != ERROR_SUCCESS) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
289 |
return VALUE_UNKNOWN; |
2 | 290 |
} |
291 |
} |
|
292 |
||
293 |
/* |
|
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
294 |
* Get the number of subkeys of the "Time Zones" registry for |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
295 |
* enumeration. |
2 | 296 |
*/ |
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
297 |
ret = RegQueryInfoKey(hKey, NULL, NULL, NULL, &nSubKeys, |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
298 |
NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
2 | 299 |
if (ret != ERROR_SUCCESS) { |
300 |
goto err; |
|
301 |
} |
|
302 |
||
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
303 |
/* |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
304 |
* Compare to the "Std" value of each subkey and find the entry that |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
305 |
* matches the current control panel setting. |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
306 |
*/ |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
307 |
onlyMapID = 0; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
308 |
for (i = 0; i < nSubKeys; ++i) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
309 |
DWORD size = sizeof(subKeyName); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
310 |
ret = RegEnumKeyEx(hKey, i, subKeyName, &size, NULL, NULL, NULL, NULL); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
311 |
if (ret != ERROR_SUCCESS) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
312 |
goto err; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
313 |
} |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
314 |
ret = RegOpenKeyEx(hKey, subKeyName, 0, KEY_READ, (PHKEY)&hSubKey); |
2 | 315 |
if (ret != ERROR_SUCCESS) { |
316 |
goto err; |
|
317 |
} |
|
318 |
||
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
319 |
size = sizeof(szValue); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
320 |
ret = getValueInRegistry(hSubKey, STD_NAME, &valueType, |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
321 |
szValue, &size); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
322 |
if (ret != ERROR_SUCCESS) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
323 |
/* |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
324 |
* NT 4.0 SP3 fails here since it doesn't have the "Std" |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
325 |
* entry in the Time Zones registry. |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
326 |
*/ |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
327 |
RegCloseKey(hSubKey); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
328 |
onlyMapID = 1; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
329 |
ret = RegOpenKeyExW(hKey, stdNamePtr, 0, KEY_READ, (PHKEY)&hSubKey); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
330 |
if (ret != ERROR_SUCCESS) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
331 |
goto err; |
2 | 332 |
} |
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
333 |
break; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
334 |
} |
2 | 335 |
|
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
336 |
if (wcscmp((WCHAR *)szValue, stdNamePtr) == 0) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
337 |
/* |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
338 |
* Some localized Win32 platforms use a same name to |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
339 |
* different time zones. So, we can't rely only on the name |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
340 |
* here. We need to check GMT offsets and transition dates |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
341 |
* to make sure it's the registry of the current time |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
342 |
* zone. |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
343 |
*/ |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
344 |
DWORD tziValueSize = sizeof(tempTzi); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
345 |
ret = RegQueryValueEx(hSubKey, "TZI", NULL, &valueType, |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
346 |
(unsigned char *) &tempTzi, &tziValueSize); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
347 |
if (ret == ERROR_SUCCESS) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
348 |
if ((tzi.Bias != tempTzi.bias) || |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
349 |
(memcmp((const void *) &tzi.StandardDate, |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
350 |
(const void *) &tempTzi.stdDate, |
2 | 351 |
sizeof(SYSTEMTIME)) != 0)) { |
352 |
goto out; |
|
353 |
} |
|
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
354 |
|
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
355 |
if (tzi.DaylightBias != 0) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
356 |
if ((tzi.DaylightBias != tempTzi.dstBias) || |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
357 |
(memcmp((const void *) &tzi.DaylightDate, |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
358 |
(const void *) &tempTzi.dstDate, |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
359 |
sizeof(SYSTEMTIME)) != 0)) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
360 |
goto out; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
361 |
} |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
362 |
} |
2 | 363 |
} |
364 |
||
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
365 |
/* |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
366 |
* found matched record, terminate search |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
367 |
*/ |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
368 |
strcpy(winZoneName, subKeyName); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
369 |
break; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
370 |
} |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
371 |
out: |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
372 |
(void) RegCloseKey(hSubKey); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
373 |
} |
2 | 374 |
|
375 |
/* |
|
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
376 |
* Get the "MapID" value of the registry to be able to eliminate |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
377 |
* duplicated key names later. |
2 | 378 |
*/ |
29930
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
379 |
valueSize = MAX_MAPID_LENGTH; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
380 |
ret = RegQueryValueExA(hSubKey, "MapID", NULL, &valueType, winMapID, &valueSize); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
381 |
(void) RegCloseKey(hSubKey); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
382 |
(void) RegCloseKey(hKey); |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
383 |
|
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
384 |
if (ret != ERROR_SUCCESS) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
385 |
/* |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
386 |
* Vista doesn't have mapID. VALUE_UNKNOWN should be returned |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
387 |
* only for Windows NT. |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
388 |
*/ |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
389 |
if (onlyMapID == 1) { |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
390 |
return VALUE_UNKNOWN; |
d816cb0064ee
7044727: (tz) TimeZone.getDefault() call returns incorrect value in Windows terminal session
okutsu
parents:
29227
diff
changeset
|
391 |
} |
2 | 392 |
} |
393 |
} |
|
394 |
||
395 |
return VALUE_KEY; |
|
396 |
||
397 |
err: |
|
398 |
if (hKey != NULL) { |
|
399 |
(void) RegCloseKey(hKey); |
|
400 |
} |
|
401 |
return VALUE_UNKNOWN; |
|
402 |
} |
|
403 |
||
404 |
/* |
|
405 |
* The mapping table file name. |
|
406 |
*/ |
|
407 |
#define MAPPINGS_FILE "\\lib\\tzmappings" |
|
408 |
||
409 |
/* |
|
410 |
* Index values for the mapping table. |
|
411 |
*/ |
|
412 |
#define TZ_WIN_NAME 0 |
|
413 |
#define TZ_MAPID 1 |
|
414 |
#define TZ_REGION 2 |
|
415 |
#define TZ_JAVA_NAME 3 |
|
416 |
||
417 |
#define TZ_NITEMS 4 /* number of items (fields) */ |
|
418 |
||
419 |
/* |
|
420 |
* Looks up the mapping table (tzmappings) and returns a Java time |
|
421 |
* zone ID (e.g., "America/Los_Angeles") if found. Otherwise, NULL is |
|
422 |
* returned. |
|
423 |
* |
|
424 |
* value_type is one of the following values: |
|
425 |
* VALUE_KEY for exact key matching |
|
24508
b4afda4d4fa1
8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending
okutsu
parents:
14177
diff
changeset
|
426 |
* VALUE_MAPID for MapID (this is |
2 | 427 |
* required for the old Windows, such as NT 4.0 SP3). |
428 |
*/ |
|
429 |
static char *matchJavaTZ(const char *java_home_dir, int value_type, char *tzName, |
|
24508
b4afda4d4fa1
8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending
okutsu
parents:
14177
diff
changeset
|
430 |
char *mapID) |
2 | 431 |
{ |
432 |
int line; |
|
433 |
int IDmatched = 0; |
|
434 |
FILE *fp; |
|
435 |
char *javaTZName = NULL; |
|
436 |
char *items[TZ_NITEMS]; |
|
24508
b4afda4d4fa1
8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending
okutsu
parents:
14177
diff
changeset
|
437 |
char *mapFileName; |
2 | 438 |
char lineBuffer[MAX_ZONE_CHAR * 4]; |
24508
b4afda4d4fa1
8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending
okutsu
parents:
14177
diff
changeset
|
439 |
int noMapID = *mapID == '\0'; /* no mapID on Vista and later */ |
50464
102ae98c917c
8204539: improve error messages in matchJavaTZ [windows]
mbaesken
parents:
47216
diff
changeset
|
440 |
int offset = 0; |
102ae98c917c
8204539: improve error messages in matchJavaTZ [windows]
mbaesken
parents:
47216
diff
changeset
|
441 |
const char* errorMessage = "unknown error"; |
2 | 442 |
|
24508
b4afda4d4fa1
8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending
okutsu
parents:
14177
diff
changeset
|
443 |
mapFileName = malloc(strlen(java_home_dir) + strlen(MAPPINGS_FILE) + 1); |
b4afda4d4fa1
8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending
okutsu
parents:
14177
diff
changeset
|
444 |
if (mapFileName == NULL) { |
b4afda4d4fa1
8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending
okutsu
parents:
14177
diff
changeset
|
445 |
return NULL; |
b4afda4d4fa1
8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending
okutsu
parents:
14177
diff
changeset
|
446 |
} |
2 | 447 |
strcpy(mapFileName, java_home_dir); |
448 |
strcat(mapFileName, MAPPINGS_FILE); |
|
449 |
||
450 |
if ((fp = fopen(mapFileName, "r")) == NULL) { |
|
451 |
jio_fprintf(stderr, "can't open %s.\n", mapFileName); |
|
24508
b4afda4d4fa1
8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending
okutsu
parents:
14177
diff
changeset
|
452 |
free((void *) mapFileName); |
2 | 453 |
return NULL; |
454 |
} |
|
24508
b4afda4d4fa1
8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending
okutsu
parents:
14177
diff
changeset
|
455 |
free((void *) mapFileName); |
2 | 456 |
|
457 |
line = 0; |
|
458 |
while (fgets(lineBuffer, sizeof(lineBuffer), fp) != NULL) { |
|
459 |
char *start, *idx, *endp; |
|
460 |
int itemIndex = 0; |
|
461 |
||
462 |
line++; |
|
463 |
start = idx = lineBuffer; |
|
464 |
endp = &lineBuffer[sizeof(lineBuffer)]; |
|
465 |
||
466 |
/* |
|
467 |
* Ignore comment and blank lines. |
|
468 |
*/ |
|
469 |
if (*idx == '#' || *idx == '\n') { |
|
470 |
continue; |
|
471 |
} |
|
472 |
||
473 |
for (itemIndex = 0; itemIndex < TZ_NITEMS; itemIndex++) { |
|
474 |
items[itemIndex] = start; |
|
475 |
while (*idx && *idx != ':') { |
|
476 |
if (++idx >= endp) { |
|
50464
102ae98c917c
8204539: improve error messages in matchJavaTZ [windows]
mbaesken
parents:
47216
diff
changeset
|
477 |
errorMessage = "premature end of line"; |
102ae98c917c
8204539: improve error messages in matchJavaTZ [windows]
mbaesken
parents:
47216
diff
changeset
|
478 |
offset = (int)(idx - lineBuffer); |
2 | 479 |
goto illegal_format; |
480 |
} |
|
481 |
} |
|
482 |
if (*idx == '\0') { |
|
50464
102ae98c917c
8204539: improve error messages in matchJavaTZ [windows]
mbaesken
parents:
47216
diff
changeset
|
483 |
errorMessage = "illegal null character found"; |
102ae98c917c
8204539: improve error messages in matchJavaTZ [windows]
mbaesken
parents:
47216
diff
changeset
|
484 |
offset = (int)(idx - lineBuffer); |
2 | 485 |
goto illegal_format; |
486 |
} |
|
487 |
*idx++ = '\0'; |
|
488 |
start = idx; |
|
489 |
} |
|
490 |
||
491 |
if (*idx != '\n') { |
|
50464
102ae98c917c
8204539: improve error messages in matchJavaTZ [windows]
mbaesken
parents:
47216
diff
changeset
|
492 |
errorMessage = "illegal non-newline character found"; |
102ae98c917c
8204539: improve error messages in matchJavaTZ [windows]
mbaesken
parents:
47216
diff
changeset
|
493 |
offset = (int)(idx - lineBuffer); |
2 | 494 |
goto illegal_format; |
495 |
} |
|
496 |
||
497 |
if (noMapID || strcmp(mapID, items[TZ_MAPID]) == 0) { |
|
498 |
/* |
|
499 |
* When there's no mapID, we need to scan items until the |
|
500 |
* exact match is found or the end of data is detected. |
|
501 |
*/ |
|
502 |
if (!noMapID) { |
|
503 |
IDmatched = 1; |
|
504 |
} |
|
505 |
if (strcmp(items[TZ_WIN_NAME], tzName) == 0) { |
|
506 |
/* |
|
507 |
* Found the time zone in the mapping table. |
|
508 |
*/ |
|
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
5506
diff
changeset
|
509 |
javaTZName = _strdup(items[TZ_JAVA_NAME]); |
2 | 510 |
break; |
511 |
} |
|
512 |
} else { |
|
513 |
if (IDmatched == 1) { |
|
514 |
/* |
|
515 |
* No need to look up the mapping table further. |
|
516 |
*/ |
|
517 |
break; |
|
518 |
} |
|
519 |
} |
|
520 |
} |
|
521 |
fclose(fp); |
|
522 |
||
523 |
return javaTZName; |
|
524 |
||
525 |
illegal_format: |
|
526 |
(void) fclose(fp); |
|
50464
102ae98c917c
8204539: improve error messages in matchJavaTZ [windows]
mbaesken
parents:
47216
diff
changeset
|
527 |
jio_fprintf(stderr, "Illegal format in tzmappings file: %s at line %d, offset %d.\n", |
102ae98c917c
8204539: improve error messages in matchJavaTZ [windows]
mbaesken
parents:
47216
diff
changeset
|
528 |
errorMessage, line, offset); |
2 | 529 |
return NULL; |
530 |
} |
|
531 |
||
532 |
/* |
|
533 |
* Detects the platform time zone which maps to a Java time zone ID. |
|
534 |
*/ |
|
24508
b4afda4d4fa1
8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending
okutsu
parents:
14177
diff
changeset
|
535 |
char *findJavaTZ_md(const char *java_home_dir) |
2 | 536 |
{ |
537 |
char winZoneName[MAX_ZONE_CHAR]; |
|
538 |
char winMapID[MAX_MAPID_LENGTH]; |
|
539 |
char *std_timezone = NULL; |
|
540 |
int result; |
|
541 |
||
542 |
winMapID[0] = 0; |
|
543 |
result = getWinTimeZone(winZoneName, winMapID); |
|
544 |
||
545 |
if (result != VALUE_UNKNOWN) { |
|
546 |
if (result == VALUE_GMTOFFSET) { |
|
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
5506
diff
changeset
|
547 |
std_timezone = _strdup(winZoneName); |
2 | 548 |
} else { |
549 |
std_timezone = matchJavaTZ(java_home_dir, result, |
|
24508
b4afda4d4fa1
8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending
okutsu
parents:
14177
diff
changeset
|
550 |
winZoneName, winMapID); |
29227
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
551 |
if (std_timezone == NULL) { |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
552 |
std_timezone = getGMTOffsetID(); |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
553 |
} |
2 | 554 |
} |
555 |
} |
|
556 |
return std_timezone; |
|
557 |
} |
|
558 |
||
559 |
/** |
|
29227
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
560 |
* Returns a GMT-offset-based time zone ID. |
2 | 561 |
*/ |
562 |
char * |
|
563 |
getGMTOffsetID() |
|
564 |
{ |
|
29227
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
565 |
LONG bias = 0; |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
566 |
LONG ret; |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
567 |
HANDLE hKey = NULL; |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
568 |
char zonename[32]; |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
569 |
|
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
570 |
// Obtain the current GMT offset value of ActiveTimeBias. |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
571 |
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_CURRENT_TZ_KEY, 0, |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
572 |
KEY_READ, (PHKEY)&hKey); |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
573 |
if (ret == ERROR_SUCCESS) { |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
574 |
DWORD val; |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
575 |
DWORD bufSize = sizeof(val); |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
576 |
ULONG valueType = 0; |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
577 |
ret = RegQueryValueExA(hKey, "ActiveTimeBias", |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
578 |
NULL, &valueType, (LPBYTE) &val, &bufSize); |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
579 |
if (ret == ERROR_SUCCESS) { |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
580 |
bias = (LONG) val; |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
581 |
} |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
582 |
(void) RegCloseKey(hKey); |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
583 |
} |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
584 |
|
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
585 |
// If we can't get the ActiveTimeBias value, use Bias of TimeZoneInformation. |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
586 |
// Note: Bias doesn't reflect current daylight saving. |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
587 |
if (ret != ERROR_SUCCESS) { |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
588 |
TIME_ZONE_INFORMATION tzi; |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
589 |
if (GetTimeZoneInformation(&tzi) != TIME_ZONE_ID_INVALID) { |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
590 |
bias = tzi.Bias; |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
591 |
} |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
592 |
} |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
593 |
|
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
594 |
customZoneName(bias, zonename); |
2ef8d6233715
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents:
25859
diff
changeset
|
595 |
return _strdup(zonename); |
2 | 596 |
} |