jdk/src/java.base/windows/native/libjava/TimeZone_md.c
author okutsu
Mon, 02 Mar 2015 11:48:08 +0900
changeset 29227 2ef8d6233715
parent 25859 3317bb8137f4
child 29930 d816cb0064ee
permissions -rw-r--r--
8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings Reviewed-by: peytoia
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
29227
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
     2
 * Copyright (c) 1999, 2015, 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
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    TIME_ZONE_INFORMATION tzi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    OSVERSIONINFO ver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    int onlyMapID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    HANDLE hKey = NULL, hSubKey = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    LONG ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    DWORD nSubKeys, i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    ULONG valueType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    TCHAR subKeyName[MAX_ZONE_CHAR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    TCHAR szValue[MAX_ZONE_CHAR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    WCHAR stdNameInReg[MAX_ZONE_CHAR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    TziValue tempTzi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    WCHAR *stdNamePtr = tzi.StandardName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    DWORD valueSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    DWORD timeType;
12849
1e155a915581 7094176: (tz) Incorrect TimeZone display name when DST not applicable / disabled
youdwei
parents: 7668
diff changeset
   164
    int isVista;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Get the current time zone setting of the platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    timeType = GetTimeZoneInformation(&tzi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    if (timeType == TIME_ZONE_ID_INVALID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Determine if this is an NT system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    ver.dwOSVersionInfoSize = sizeof(ver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    GetVersionEx(&ver);
14177
007c2f91d22b 7186817: Remove Windows 95/98/ME Support
dxu
parents: 12849
diff changeset
   179
    isVista = ver.dwMajorVersion >= 6;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_CURRENT_TZ_KEY, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                       KEY_READ, (PHKEY)&hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    if (ret == ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        DWORD val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        DWORD bufSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
         * Determine if auto-daylight time adjustment is turned off.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        valueType = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        bufSize = sizeof(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        ret = RegQueryValueExA(hKey, "DisableAutoDaylightTimeSet",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                               NULL, &valueType, (LPBYTE) &val, &bufSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
         * Vista uses the different key name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if (ret != ERROR_SUCCESS) {
29227
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   198
            bufSize = sizeof(val);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            ret = RegQueryValueExA(hKey, "DynamicDaylightTimeDisabled",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                                   NULL, &valueType, (LPBYTE) &val, &bufSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
12849
1e155a915581 7094176: (tz) Incorrect TimeZone display name when DST not applicable / disabled
youdwei
parents: 7668
diff changeset
   202
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (ret == ERROR_SUCCESS) {
12849
1e155a915581 7094176: (tz) Incorrect TimeZone display name when DST not applicable / disabled
youdwei
parents: 7668
diff changeset
   204
            int daylightSavingsUpdateDisabledOther = val == 1 && tzi.DaylightDate.wMonth != 0;
1e155a915581 7094176: (tz) Incorrect TimeZone display name when DST not applicable / disabled
youdwei
parents: 7668
diff changeset
   205
            int daylightSavingsUpdateDisabledVista = val == 1;
1e155a915581 7094176: (tz) Incorrect TimeZone display name when DST not applicable / disabled
youdwei
parents: 7668
diff changeset
   206
            int daylightSavingsUpdateDisabled = isVista ? daylightSavingsUpdateDisabledVista : daylightSavingsUpdateDisabledOther;
1e155a915581 7094176: (tz) Incorrect TimeZone display name when DST not applicable / disabled
youdwei
parents: 7668
diff changeset
   207
1e155a915581 7094176: (tz) Incorrect TimeZone display name when DST not applicable / disabled
youdwei
parents: 7668
diff changeset
   208
            if (daylightSavingsUpdateDisabled) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                (void) RegCloseKey(hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                customZoneName(tzi.Bias, winZoneName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                return VALUE_GMTOFFSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
         * Vista has the key for the current "Time Zones" entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
         */
12849
1e155a915581 7094176: (tz) Incorrect TimeZone display name when DST not applicable / disabled
youdwei
parents: 7668
diff changeset
   218
        if (isVista) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            valueType = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            bufSize = MAX_ZONE_CHAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            ret = RegQueryValueExA(hKey, "TimeZoneKeyName", NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                                   &valueType, (LPBYTE) winZoneName, &bufSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            (void) RegCloseKey(hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            return VALUE_KEY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
         * Win32 problem: If the length of the standard time name is equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
         * to (or probably longer than) 32 in the registry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
         * GetTimeZoneInformation() on NT returns a null string as its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
         * standard time name. We need to work around this problem by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
         * getting the same information from the TimeZoneInformation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
         * registry. The function on Win98 seems to return its key name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
         * We can't do anything in that case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (tzi.StandardName[0] == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            bufSize = sizeof(stdNameInReg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            ret = getValueInRegistry(hKey, STANDARD_NAME, &valueType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                                     (LPBYTE) stdNameInReg, &bufSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            stdNamePtr = stdNameInReg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        (void) RegCloseKey(hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Open the "Time Zones" registry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, NT_TZ_KEY, 0, KEY_READ, (PHKEY)&hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_TZ_KEY, 0, KEY_READ, (PHKEY)&hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
         * If both failed, then give up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            return VALUE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Get the number of subkeys of the "Time Zones" registry for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * enumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    ret = RegQueryInfoKey(hKey, NULL, NULL, NULL, &nSubKeys,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                          NULL, NULL, NULL, NULL, NULL, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Compare to the "Std" value of each subkey and find the entry that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * matches the current control panel setting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    onlyMapID = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    for (i = 0; i < nSubKeys; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        DWORD size = sizeof(subKeyName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        ret = RegEnumKeyEx(hKey, i, subKeyName, &size, NULL, NULL, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        ret = RegOpenKeyEx(hKey, subKeyName, 0, KEY_READ, (PHKEY)&hSubKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        size = sizeof(szValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        ret = getValueInRegistry(hSubKey, STD_NAME, &valueType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                                 szValue, &size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
             * NT 4.0 SP3 fails here since it doesn't have the "Std"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
             * entry in the Time Zones registry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            RegCloseKey(hSubKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            onlyMapID = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            ret = RegOpenKeyExW(hKey, stdNamePtr, 0, KEY_READ, (PHKEY)&hSubKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if (wcscmp((WCHAR *)szValue, stdNamePtr) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
             * Some localized Win32 platforms use a same name to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
             * different time zones. So, we can't rely only on the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
             * here. We need to check GMT offsets and transition dates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
             * to make sure it's the registry of the current time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
             * zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            DWORD tziValueSize = sizeof(tempTzi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            ret = RegQueryValueEx(hSubKey, "TZI", NULL, &valueType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                                  (unsigned char *) &tempTzi, &tziValueSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            if (ret == ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                if ((tzi.Bias != tempTzi.bias) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                    (memcmp((const void *) &tzi.StandardDate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                            (const void *) &tempTzi.stdDate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                            sizeof(SYSTEMTIME)) != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                        goto out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                if (tzi.DaylightBias != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                    if ((tzi.DaylightBias != tempTzi.dstBias) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                        (memcmp((const void *) &tzi.DaylightDate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                                (const void *) &tempTzi.dstDate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                                sizeof(SYSTEMTIME)) != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                        goto out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
             * found matched record, terminate search
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            strcpy(winZoneName, subKeyName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    out:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        (void) RegCloseKey(hSubKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * Get the "MapID" value of the registry to be able to eliminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * duplicated key names later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    valueSize = MAX_MAPID_LENGTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    ret = RegQueryValueExA(hSubKey, "MapID", NULL, &valueType, winMapID, &valueSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    (void) RegCloseKey(hSubKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    (void) RegCloseKey(hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
         * Vista doesn't have mapID. VALUE_UNKNOWN should be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
         * only for Windows NT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        if (onlyMapID == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            return VALUE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    return VALUE_KEY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
 err:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    if (hKey != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        (void) RegCloseKey(hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    return VALUE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
 * The mapping table file name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
#define MAPPINGS_FILE "\\lib\\tzmappings"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
 * Index values for the mapping table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
#define TZ_WIN_NAME     0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
#define TZ_MAPID        1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
#define TZ_REGION       2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
#define TZ_JAVA_NAME    3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
#define TZ_NITEMS       4       /* number of items (fields) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
 * Looks up the mapping table (tzmappings) and returns a Java time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
 * zone ID (e.g., "America/Los_Angeles") if found. Otherwise, NULL is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
 * returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
 * value_type is one of the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
 *      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
   397
 *      VALUE_MAPID for MapID (this is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
 *      required for the old Windows, such as NT 4.0 SP3).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
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
   401
                         char *mapID)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    int line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    int IDmatched = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    FILE *fp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    char *javaTZName = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    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
   408
    char *mapFileName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    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
   410
    int noMapID = *mapID == '\0';       /* no mapID on Vista and later */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
24508
b4afda4d4fa1 8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending
okutsu
parents: 14177
diff changeset
   412
    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
   413
    if (mapFileName == NULL) {
b4afda4d4fa1 8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending
okutsu
parents: 14177
diff changeset
   414
        return NULL;
b4afda4d4fa1 8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending
okutsu
parents: 14177
diff changeset
   415
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    strcpy(mapFileName, java_home_dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    strcat(mapFileName, MAPPINGS_FILE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    if ((fp = fopen(mapFileName, "r")) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        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
   421
        free((void *) mapFileName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
24508
b4afda4d4fa1 8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending
okutsu
parents: 14177
diff changeset
   424
    free((void *) mapFileName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    line = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    while (fgets(lineBuffer, sizeof(lineBuffer), fp) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        char *start, *idx, *endp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        int itemIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        line++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        start = idx = lineBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        endp = &lineBuffer[sizeof(lineBuffer)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
         * Ignore comment and blank lines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        if (*idx == '#' || *idx == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        for (itemIndex = 0; itemIndex < TZ_NITEMS; itemIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            items[itemIndex] = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            while (*idx && *idx != ':') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                if (++idx >= endp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    goto illegal_format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            if (*idx == '\0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                goto illegal_format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            *idx++ = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            start = idx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        if (*idx != '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            goto illegal_format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        if (noMapID || strcmp(mapID, items[TZ_MAPID]) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
             * When there's no mapID, we need to scan items until the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
             * exact match is found or the end of data is detected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            if (!noMapID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                IDmatched = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            if (strcmp(items[TZ_WIN_NAME], tzName) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                 * Found the time zone in the mapping table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                 */
6850
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 5506
diff changeset
   472
                javaTZName = _strdup(items[TZ_JAVA_NAME]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            if (IDmatched == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                 * No need to look up the mapping table further.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    fclose(fp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    return javaTZName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
 illegal_format:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    (void) fclose(fp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    jio_fprintf(stderr, "tzmappings: Illegal format at line %d.\n", line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
 * Detects the platform time zone which maps to a Java time zone ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
 */
24508
b4afda4d4fa1 8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending
okutsu
parents: 14177
diff changeset
   497
char *findJavaTZ_md(const char *java_home_dir)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    char winZoneName[MAX_ZONE_CHAR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    char winMapID[MAX_MAPID_LENGTH];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    char *std_timezone = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    int  result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    winMapID[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    result = getWinTimeZone(winZoneName, winMapID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    if (result != VALUE_UNKNOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        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
   509
            std_timezone = _strdup(winZoneName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            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
   512
                                       winZoneName, winMapID);
29227
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   513
            if (std_timezone == NULL) {
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   514
                std_timezone = getGMTOffsetID();
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   515
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    return std_timezone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
/**
29227
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   522
 * Returns a GMT-offset-based time zone ID.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
getGMTOffsetID()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
{
29227
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   527
    LONG bias = 0;
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   528
    LONG ret;
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   529
    HANDLE hKey = NULL;
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   530
    char zonename[32];
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   531
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   532
    // 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
   533
    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
   534
                       KEY_READ, (PHKEY)&hKey);
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   535
    if (ret == ERROR_SUCCESS) {
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   536
        DWORD val;
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   537
        DWORD bufSize = sizeof(val);
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   538
        ULONG valueType = 0;
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   539
        ret = RegQueryValueExA(hKey, "ActiveTimeBias",
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   540
                               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
   541
        if (ret == ERROR_SUCCESS) {
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   542
            bias = (LONG) val;
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   543
        }
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   544
        (void) RegCloseKey(hKey);
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   545
    }
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   546
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   547
    // 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
   548
    // 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
   549
    if (ret != ERROR_SUCCESS) {
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   550
        TIME_ZONE_INFORMATION tzi;
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   551
        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
   552
            bias = tzi.Bias;
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   553
        }
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   554
    }
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   555
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   556
    customZoneName(bias, zonename);
2ef8d6233715 8072602: Unpredictable timezone on Windows when OS's timezone is not found in tzmappings
okutsu
parents: 25859
diff changeset
   557
    return _strdup(zonename);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
}