src/java.base/windows/native/libjava/TimeZone_md.c
author mbaesken
Fri, 08 Jun 2018 13:06:08 +0200
changeset 50464 102ae98c917c
parent 47216 71c04702a3d5
child 51730 cd0775f67ab0
permissions -rw-r--r--
8204539: improve error messages in matchJavaTZ [windows] Reviewed-by: coffeys, clanger, goetz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <windows.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "TimeZone_md.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#define VALUE_UNKNOWN           0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#define VALUE_KEY               1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#define VALUE_MAPID             2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#define VALUE_GMTOFFSET         3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#define MAX_ZONE_CHAR           256
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#define MAX_MAPID_LENGTH        32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#define NT_TZ_KEY               "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#define WIN_TZ_KEY              "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Time Zones"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#define WIN_CURRENT_TZ_KEY      "System\\CurrentControlSet\\Control\\TimeZoneInformation"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
typedef struct _TziValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    LONG        bias;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    LONG        stdBias;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    LONG        dstBias;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    SYSTEMTIME  stdDate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    SYSTEMTIME  dstDate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
} TziValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * Registry key names
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
static void *keyNames[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    (void *) L"StandardName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    (void *) "StandardName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    (void *) L"Std",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    (void *) "Std"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Indices to keyNames[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#define STANDARD_NAME           0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#define STD_NAME                2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * Calls RegQueryValueEx() to get the value for the specified key. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * the platform is NT, 2000 or XP, it calls the Unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * version. Otherwise, it calls the ANSI version and converts the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * value to Unicode. In this case, it assumes that the current ANSI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * Code Page is the same as the native platform code page (e.g., Code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * Page 932 for the Japanese Windows systems.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * `keyIndex' is an index value to the keyNames in Unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * (WCHAR). `keyIndex' + 1 points to its ANSI value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * Returns the status value. ERROR_SUCCESS if succeeded, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * non-ERROR_SUCCESS value otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
static LONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
getValueInRegistry(HKEY hKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                   int keyIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                   LPDWORD typePtr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                   LPBYTE buf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                   LPDWORD bufLengthPtr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    LONG ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    DWORD bufLength = *bufLengthPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    char val[MAX_ZONE_CHAR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    DWORD valSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    *typePtr = 0;
14177
007c2f91d22b 7186817: Remove Windows 95/98/ME Support
dxu
parents: 12849
diff changeset
    96
    ret = RegQueryValueExW(hKey, (WCHAR *) keyNames[keyIndex], NULL,
007c2f91d22b 7186817: Remove Windows 95/98/ME Support
dxu
parents: 12849
diff changeset
    97
                           typePtr, buf, bufLengthPtr);
007c2f91d22b 7186817: Remove Windows 95/98/ME Support
dxu
parents: 12849
diff changeset
    98
    if (ret == ERROR_SUCCESS && *typePtr == REG_SZ) {
007c2f91d22b 7186817: Remove Windows 95/98/ME Support
dxu
parents: 12849
diff changeset
    99
        return ret;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    valSize = sizeof(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    ret = RegQueryValueExA(hKey, (char *) keyNames[keyIndex + 1], NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                           typePtr, val, &valSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    if (*typePtr != REG_SZ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        return ERROR_BADKEY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    len = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                              (LPCSTR) val, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                              (LPWSTR) buf, bufLength/sizeof(WCHAR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    if (len <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return ERROR_BADKEY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    return ERROR_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * Produces custom name "GMT+hh:mm" from the given bias in buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
static void customZoneName(LONG bias, char *buffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    LONG gmtOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    int sign;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    if (bias > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        gmtOffset = bias;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        sign = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        gmtOffset = -bias;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        sign = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    if (gmtOffset != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        sprintf(buffer, "GMT%c%02d:%02d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                ((sign >= 0) ? '+' : '-'),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                gmtOffset / 60,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                gmtOffset % 60);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        strcpy(buffer, "GMT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * Gets the current time zone entry in the "Time Zones" registry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
static int getWinTimeZone(char *winZoneName, char *winMapID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    LONG ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    ULONG valueType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    if (timeType == TIME_ZONE_ID_INVALID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
         * Determine if auto-daylight time adjustment is turned off.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                                sizeof(SYSTEMTIME)) != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                        goto out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    return VALUE_KEY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
 err:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    if (hKey != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        (void) RegCloseKey(hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    return VALUE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
 * The mapping table file name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
#define MAPPINGS_FILE "\\lib\\tzmappings"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
 * Index values for the mapping table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
#define TZ_WIN_NAME     0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
#define TZ_MAPID        1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
#define TZ_REGION       2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
#define TZ_JAVA_NAME    3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
#define TZ_NITEMS       4       /* number of items (fields) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
 * Looks up the mapping table (tzmappings) and returns a Java time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
 * zone ID (e.g., "America/Los_Angeles") if found. Otherwise, NULL is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
 * returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
 * value_type is one of the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
 *      required for the old Windows, such as NT 4.0 SP3).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    int line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    int IDmatched = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    FILE *fp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    char *javaTZName = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    strcpy(mapFileName, java_home_dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    strcat(mapFileName, MAPPINGS_FILE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    if ((fp = fopen(mapFileName, "r")) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    line = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    while (fgets(lineBuffer, sizeof(lineBuffer), fp) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        char *start, *idx, *endp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        int itemIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        line++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        start = idx = lineBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        endp = &lineBuffer[sizeof(lineBuffer)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
         * Ignore comment and blank lines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        if (*idx == '#' || *idx == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        for (itemIndex = 0; itemIndex < TZ_NITEMS; itemIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            items[itemIndex] = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            while (*idx && *idx != ':') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                    goto illegal_format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                goto illegal_format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            *idx++ = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            start = idx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            goto illegal_format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        if (noMapID || strcmp(mapID, items[TZ_MAPID]) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
             * When there's no mapID, we need to scan items until the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
             * exact match is found or the end of data is detected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            if (!noMapID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                IDmatched = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            if (strcmp(items[TZ_WIN_NAME], tzName) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                 * Found the time zone in the mapping table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            if (IDmatched == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                 * No need to look up the mapping table further.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    fclose(fp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    return javaTZName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
 illegal_format:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
 * Detects the platform time zone which maps to a Java time zone ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    char winZoneName[MAX_ZONE_CHAR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    char winMapID[MAX_MAPID_LENGTH];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    char *std_timezone = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    int  result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    winMapID[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    result = getWinTimeZone(winZoneName, winMapID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    if (result != VALUE_UNKNOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    return std_timezone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
getGMTOffsetID()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
}