jdk/src/windows/native/java/util/TimeZone_md.c
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 6850 56966b0a6a0d
child 12849 1e155a915581
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 6850
diff changeset
     2
 * Copyright (c) 1999, 2010, 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
static int isNT = FALSE;        /* TRUE if it is NT. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * Calls RegQueryValueEx() to get the value for the specified key. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * the platform is NT, 2000 or XP, it calls the Unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * version. Otherwise, it calls the ANSI version and converts the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * value to Unicode. In this case, it assumes that the current ANSI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * Code Page is the same as the native platform code page (e.g., Code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * Page 932 for the Japanese Windows systems.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * `keyIndex' is an index value to the keyNames in Unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * (WCHAR). `keyIndex' + 1 points to its ANSI value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * Returns the status value. ERROR_SUCCESS if succeeded, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * non-ERROR_SUCCESS value otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
static LONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
getValueInRegistry(HKEY hKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                   int keyIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                   LPDWORD typePtr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                   LPBYTE buf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                   LPDWORD bufLengthPtr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    LONG ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    DWORD bufLength = *bufLengthPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    char val[MAX_ZONE_CHAR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    DWORD valSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    *typePtr = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    if (isNT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        ret = RegQueryValueExW(hKey, (WCHAR *) keyNames[keyIndex], NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                               typePtr, buf, bufLengthPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        if (ret == ERROR_SUCCESS && *typePtr == REG_SZ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    valSize = sizeof(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    ret = RegQueryValueExA(hKey, (char *) keyNames[keyIndex + 1], NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                           typePtr, val, &valSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    if (*typePtr != REG_SZ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        return ERROR_BADKEY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    len = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                              (LPCSTR) val, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                              (LPWSTR) buf, bufLength/sizeof(WCHAR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    if (len <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return ERROR_BADKEY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    return ERROR_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * Produces custom name "GMT+hh:mm" from the given bias in buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
static void customZoneName(LONG bias, char *buffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    LONG gmtOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    int sign;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    if (bias > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        gmtOffset = bias;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        sign = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        gmtOffset = -bias;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        sign = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    if (gmtOffset != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        sprintf(buffer, "GMT%c%02d:%02d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                ((sign >= 0) ? '+' : '-'),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                gmtOffset / 60,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                gmtOffset % 60);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        strcpy(buffer, "GMT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * Gets the current time zone entry in the "Time Zones" registry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
static int getWinTimeZone(char *winZoneName, char *winMapID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    TIME_ZONE_INFORMATION tzi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    OSVERSIONINFO ver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    int onlyMapID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    HANDLE hKey = NULL, hSubKey = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    LONG ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    DWORD nSubKeys, i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    ULONG valueType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    TCHAR subKeyName[MAX_ZONE_CHAR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    TCHAR szValue[MAX_ZONE_CHAR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    WCHAR stdNameInReg[MAX_ZONE_CHAR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    TziValue tempTzi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    WCHAR *stdNamePtr = tzi.StandardName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    DWORD valueSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    DWORD timeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Get the current time zone setting of the platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    timeType = GetTimeZoneInformation(&tzi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    if (timeType == TIME_ZONE_ID_INVALID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Determine if this is an NT system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    ver.dwOSVersionInfoSize = sizeof(ver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    GetVersionEx(&ver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    isNT = ver.dwPlatformId == VER_PLATFORM_WIN32_NT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_CURRENT_TZ_KEY, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                       KEY_READ, (PHKEY)&hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    if (ret == ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        DWORD val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        DWORD bufSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
         * Determine if auto-daylight time adjustment is turned off.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        valueType = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        bufSize = sizeof(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        ret = RegQueryValueExA(hKey, "DisableAutoDaylightTimeSet",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                               NULL, &valueType, (LPBYTE) &val, &bufSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
         * Vista uses the different key name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
          bufSize = sizeof(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            ret = RegQueryValueExA(hKey, "DynamicDaylightTimeDisabled",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                                   NULL, &valueType, (LPBYTE) &val, &bufSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (ret == ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            if (val == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                (void) RegCloseKey(hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                customZoneName(tzi.Bias, winZoneName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                return VALUE_GMTOFFSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         * Vista has the key for the current "Time Zones" entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if (isNT && ver.dwMajorVersion >= 6) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            valueType = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            bufSize = MAX_ZONE_CHAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            ret = RegQueryValueExA(hKey, "TimeZoneKeyName", NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                                   &valueType, (LPBYTE) winZoneName, &bufSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            (void) RegCloseKey(hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            return VALUE_KEY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
         * Win32 problem: If the length of the standard time name is equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
         * to (or probably longer than) 32 in the registry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
         * GetTimeZoneInformation() on NT returns a null string as its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
         * standard time name. We need to work around this problem by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
         * getting the same information from the TimeZoneInformation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
         * registry. The function on Win98 seems to return its key name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
         * We can't do anything in that case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (tzi.StandardName[0] == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            bufSize = sizeof(stdNameInReg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            ret = getValueInRegistry(hKey, STANDARD_NAME, &valueType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                                     (LPBYTE) stdNameInReg, &bufSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            stdNamePtr = stdNameInReg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        (void) RegCloseKey(hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Open the "Time Zones" registry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, NT_TZ_KEY, 0, KEY_READ, (PHKEY)&hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_TZ_KEY, 0, KEY_READ, (PHKEY)&hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
         * If both failed, then give up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            return VALUE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * Get the number of subkeys of the "Time Zones" registry for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * enumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    ret = RegQueryInfoKey(hKey, NULL, NULL, NULL, &nSubKeys,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                          NULL, NULL, NULL, NULL, NULL, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * Compare to the "Std" value of each subkey and find the entry that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * matches the current control panel setting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    onlyMapID = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    for (i = 0; i < nSubKeys; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        DWORD size = sizeof(subKeyName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        ret = RegEnumKeyEx(hKey, i, subKeyName, &size, NULL, NULL, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        ret = RegOpenKeyEx(hKey, subKeyName, 0, KEY_READ, (PHKEY)&hSubKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        size = sizeof(szValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        ret = getValueInRegistry(hSubKey, STD_NAME, &valueType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                                 szValue, &size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
             * NT 4.0 SP3 fails here since it doesn't have the "Std"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
             * entry in the Time Zones registry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            RegCloseKey(hSubKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            onlyMapID = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            ret = RegOpenKeyExW(hKey, stdNamePtr, 0, KEY_READ, (PHKEY)&hSubKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        if (wcscmp((WCHAR *)szValue, stdNamePtr) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
             * Some localized Win32 platforms use a same name to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
             * different time zones. So, we can't rely only on the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
             * here. We need to check GMT offsets and transition dates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
             * to make sure it's the registry of the current time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
             * zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            DWORD tziValueSize = sizeof(tempTzi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            ret = RegQueryValueEx(hSubKey, "TZI", NULL, &valueType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                                  (unsigned char *) &tempTzi, &tziValueSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            if (ret == ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                if ((tzi.Bias != tempTzi.bias) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                    (memcmp((const void *) &tzi.StandardDate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                            (const void *) &tempTzi.stdDate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                            sizeof(SYSTEMTIME)) != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                        goto out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                if (tzi.DaylightBias != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                    if ((tzi.DaylightBias != tempTzi.dstBias) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                        (memcmp((const void *) &tzi.DaylightDate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                                (const void *) &tempTzi.dstDate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                                sizeof(SYSTEMTIME)) != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                        goto out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                }
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
             * found matched record, terminate search
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            strcpy(winZoneName, subKeyName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    out:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        (void) RegCloseKey(hSubKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Get the "MapID" value of the registry to be able to eliminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * duplicated key names later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    valueSize = MAX_MAPID_LENGTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    ret = RegQueryValueExA(hSubKey, "MapID", NULL, &valueType, winMapID, &valueSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    (void) RegCloseKey(hSubKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    (void) RegCloseKey(hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
         * Vista doesn't have mapID. VALUE_UNKNOWN should be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
         * only for Windows NT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        if (onlyMapID == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            return VALUE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    return VALUE_KEY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
 err:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    if (hKey != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        (void) RegCloseKey(hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    return VALUE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
 * The mapping table file name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
#define MAPPINGS_FILE "\\lib\\tzmappings"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
 * Index values for the mapping table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
#define TZ_WIN_NAME     0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
#define TZ_MAPID        1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
#define TZ_REGION       2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
#define TZ_JAVA_NAME    3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
#define TZ_NITEMS       4       /* number of items (fields) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
 * Looks up the mapping table (tzmappings) and returns a Java time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
 * zone ID (e.g., "America/Los_Angeles") if found. Otherwise, NULL is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
 * returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
 * value_type is one of the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
 *      VALUE_KEY for exact key matching
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
 *      VALUE_MAPID for MapID and country-based mapping (this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
 *      required for the old Windows, such as NT 4.0 SP3).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
static char *matchJavaTZ(const char *java_home_dir, int value_type, char *tzName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                         char *mapID, const char *country)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    int line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    int IDmatched = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    FILE *fp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    char *javaTZName = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    char *items[TZ_NITEMS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    char mapFileName[_MAX_PATH + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    char lineBuffer[MAX_ZONE_CHAR * 4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    char bestMatch[MAX_ZONE_CHAR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    int noMapID = *mapID == '\0';       /* no mapID on Vista */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    bestMatch[0] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    strcpy(mapFileName, java_home_dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    strcat(mapFileName, MAPPINGS_FILE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    if ((fp = fopen(mapFileName, "r")) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        jio_fprintf(stderr, "can't open %s.\n", mapFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    line = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    while (fgets(lineBuffer, sizeof(lineBuffer), fp) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        char *start, *idx, *endp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        int itemIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        line++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        start = idx = lineBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        endp = &lineBuffer[sizeof(lineBuffer)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
         * Ignore comment and blank lines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        if (*idx == '#' || *idx == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        for (itemIndex = 0; itemIndex < TZ_NITEMS; itemIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            items[itemIndex] = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            while (*idx && *idx != ':') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                if (++idx >= endp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    goto illegal_format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            if (*idx == '\0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                goto illegal_format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            *idx++ = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            start = idx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        if (*idx != '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            goto illegal_format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        if (noMapID || strcmp(mapID, items[TZ_MAPID]) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
             * When there's no mapID, we need to scan items until the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
             * exact match is found or the end of data is detected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            if (!noMapID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                IDmatched = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            if (strcmp(items[TZ_WIN_NAME], tzName) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                 * Found the time zone in the mapping table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                 */
6850
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 5506
diff changeset
   467
                javaTZName = _strdup(items[TZ_JAVA_NAME]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
             * Try to find the most likely time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            if (*items[TZ_REGION] == '\0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                strncpy(bestMatch, items[TZ_JAVA_NAME], MAX_ZONE_CHAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            } else if (country != NULL && strcmp(items[TZ_REGION], country) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                if (value_type == VALUE_MAPID) {
6850
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 5506
diff changeset
   477
                    javaTZName = _strdup(items[TZ_JAVA_NAME]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                strncpy(bestMatch, items[TZ_JAVA_NAME], MAX_ZONE_CHAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            if (IDmatched == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                 * No need to look up the mapping table further.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    fclose(fp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    if (javaTZName == NULL && bestMatch[0] != '\0') {
6850
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 5506
diff changeset
   494
        javaTZName = _strdup(bestMatch);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    return javaTZName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
 illegal_format:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    (void) fclose(fp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    jio_fprintf(stderr, "tzmappings: Illegal format at line %d.\n", line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
 * Detects the platform time zone which maps to a Java time zone ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
char *findJavaTZ_md(const char *java_home_dir, const char *country)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    char winZoneName[MAX_ZONE_CHAR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    char winMapID[MAX_MAPID_LENGTH];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    char *std_timezone = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    int  result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    winMapID[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    result = getWinTimeZone(winZoneName, winMapID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    if (result != VALUE_UNKNOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        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
   519
            std_timezone = _strdup(winZoneName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            std_timezone = matchJavaTZ(java_home_dir, result,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                                       winZoneName, winMapID, country);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    return std_timezone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
 * Returns a GMT-offset-based time zone ID. On Win32, it always return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
 * NULL since the fall back is performed in getWinTimeZone().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
getGMTOffsetID()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
}