jdk/src/windows/native/java/lang/java_props_md.c
author naoto
Thu, 06 Feb 2014 10:06:09 -0800
changeset 22939 fc08f20ea32f
parent 19190 50a4d01485a1
child 23010 6dadb192ad81
permissions -rw-r--r--
8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending Reviewed-by: msheppar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 12873
diff changeset
     2
 * Copyright (c) 1998, 2012, 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: 5168
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: 5168
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: 5168
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5168
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5168
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
15291
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
    26
/* Access APIs for Windows Vista and above */
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
    27
#ifndef _WIN32_WINNT
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
    28
#define _WIN32_WINNT 0x0601
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
    29
#endif
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
    30
22939
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
    31
#include "jni.h"
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
    32
#include "jni_util.h"
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
    33
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <windows.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <shlobj.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include <objidl.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <locale.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <sys/timeb.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include <tchar.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
11906
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
    42
#include <stdlib.h>
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
    43
#include <Wincon.h>
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
    44
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#include "locale_str.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#include "java_props.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#ifndef VER_PLATFORM_WIN32_WINDOWS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#define VER_PLATFORM_WIN32_WINDOWS 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
1626
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
    52
#ifndef PROCESSOR_ARCHITECTURE_AMD64
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
    53
#define PROCESSOR_ARCHITECTURE_AMD64 9
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
    54
#endif
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
    55
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
    56
typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
22939
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
    57
static boolean SetupI18nProps(LCID lcid, char** language, char** script, char** country,
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    58
               char** variant, char** encoding);
1626
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
    59
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
    60
#define PROPSIZE 9      // eight-letter + null terminator
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
    61
#define SNAMESIZE 86    // max number of chars for LOCALE_SNAME is 85
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
    62
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    63
static char *
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    64
getEncodingInternal(LCID lcid)
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    65
{
22939
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
    66
    int codepage;
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    67
    char * ret = malloc(16);
22939
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
    68
    if (ret == NULL) {
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
    69
        return NULL;
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
    70
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    72
    if (GetLocaleInfo(lcid,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    73
                      LOCALE_IDEFAULTANSICODEPAGE,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    74
                      ret+2, 14) == 0) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    75
        codepage = 1252;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    76
    } else {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    77
        codepage = atoi(ret+2);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    78
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    80
    switch (codepage) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    81
    case 0:
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    82
        strcpy(ret, "UTF-8");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    83
        break;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    84
    case 874:     /*  9:Thai     */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    85
    case 932:     /* 10:Japanese */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    86
    case 949:     /* 12:Korean Extended Wansung */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    87
    case 950:     /* 13:Chinese (Taiwan, Hongkong, Macau) */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    88
    case 1361:    /* 15:Korean Johab */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    89
        ret[0] = 'M';
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    90
        ret[1] = 'S';
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    91
        break;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    92
    case 936:
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    93
        strcpy(ret, "GBK");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    94
        break;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    95
    case 54936:
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    96
        strcpy(ret, "GB18030");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    97
        break;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    98
    default:
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    99
        ret[0] = 'C';
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   100
        ret[1] = 'p';
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   101
        break;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   102
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   104
    //Traditional Chinese Windows should use MS950_HKSCS_XP as the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    //default encoding, if HKSCS patch has been installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    // "old" MS950 0xfa41 -> u+e001
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    // "new" MS950 0xfa41 -> u+92db
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    if (strcmp(ret, "MS950") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        TCHAR  mbChar[2] = {(char)0xfa, (char)0x41};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        WCHAR  unicodeChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        MultiByteToWideChar(CP_ACP, 0, mbChar, 2, &unicodeChar, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        if (unicodeChar == 0x92db) {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   113
            strcpy(ret, "MS950_HKSCS_XP");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        //SimpChinese Windows should use GB18030 as the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        //encoding, if gb18030 patch has been installed (on windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        //2000/XP, (1)Codepage 54936 will be available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        //(2)simsun18030.ttc will exist under system fonts dir )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (strcmp(ret, "GBK") == 0 && IsValidCodePage(54936)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            char systemPath[MAX_PATH + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            char* gb18030Font = "\\FONTS\\SimSun18030.ttc";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            FILE *f = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            if (GetWindowsDirectory(systemPath, MAX_PATH + 1) != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                strlen(systemPath) + strlen(gb18030Font) < MAX_PATH + 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                strcat(systemPath, "\\FONTS\\SimSun18030.ttc");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                if ((f = fopen(systemPath, "r")) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    fclose(f);
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   129
                    strcpy(ret, "GB18030");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
11906
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   138
static char* getConsoleEncoding()
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   139
{
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   140
    char* buf = malloc(16);
22939
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   141
    int cp;
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   142
    if (buf == NULL) {
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   143
        return NULL;
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   144
    }
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   145
    cp = GetConsoleCP();
11906
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   146
    if (cp >= 874 && cp <= 950)
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   147
        sprintf(buf, "ms%d", cp);
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   148
    else
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   149
        sprintf(buf, "cp%d", cp);
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   150
    return buf;
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   151
}
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   152
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
// Exported entries for AWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
DllExport const char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
getEncodingFromLangID(LANGID langID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
{
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   157
    return getEncodingInternal(MAKELCID(langID, SORT_DEFAULT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   160
// Returns BCP47 Language Tag
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
DllExport const char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
getJavaIDFromLangID(LANGID langID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
{
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   164
    char * elems[5]; // lang, script, ctry, variant, encoding
22939
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   165
    char * ret;
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   166
    int index;
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   167
22939
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   168
    ret = malloc(SNAMESIZE);
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   169
    if (ret == NULL) {
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   170
        return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   172
22939
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   173
    if (SetupI18nProps(MAKELCID(langID, SORT_DEFAULT),
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   174
                   &(elems[0]), &(elems[1]), &(elems[2]), &(elems[3]), &(elems[4]))) {
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   175
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   176
        // there always is the "language" tag
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   177
        strcpy(ret, elems[0]);
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   178
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   179
        // append other elements, if any
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   180
        for (index = 1; index < 4; index++) {
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   181
            if ((elems[index])[0] != '\0') {
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   182
                strcat(ret, "-");
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   183
                strcat(ret, elems[index]);
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   184
            }
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   185
        }
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   186
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   187
        for (index = 0; index < 5; index++) {
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   188
            free(elems[index]);
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   189
        }
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   190
    } else {
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   191
        ret = NULL;
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   192
    }
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   193
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   194
    return ret;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * Code to figure out the user's home directory using shell32.dll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 */
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   200
WCHAR*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
getHomeFromShell32()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
{
15291
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   203
    /*
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   204
     * Note that we don't free the memory allocated
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   205
     * by getHomeFromShell32.
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   206
     */
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   207
    static WCHAR *u_path = NULL;
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   208
    if (u_path == NULL) {
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   209
        HRESULT hr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
15291
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   211
        /*
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   212
         * SHELL32 DLL is delay load DLL and we can use the trick with
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   213
         * __try/__except block.
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   214
         */
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   215
        __try {
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   216
            /*
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   217
             * For Windows Vista and later (or patched MS OS) we need to use
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   218
             * [SHGetKnownFolderPath] call to avoid MAX_PATH length limitation.
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   219
             * Shell32.dll (version 6.0.6000 or later)
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   220
             */
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   221
            hr = SHGetKnownFolderPath(&FOLDERID_Profile, KF_FLAG_DONT_VERIFY, NULL, &u_path);
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   222
        } __except(EXCEPTION_EXECUTE_HANDLER) {
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   223
            /* Exception: no [SHGetKnownFolderPath] entry */
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   224
            hr = E_FAIL;
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   225
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
15291
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   227
        if (FAILED(hr)) {
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   228
            WCHAR path[MAX_PATH+1];
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   229
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   230
            /* fallback solution for WinXP and Windows 2000 */
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   231
            hr = SHGetFolderPathW(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, path);
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   232
            if (FAILED(hr)) {
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   233
                /* we can't find the shell folder. */
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   234
                u_path = NULL;
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   235
            } else {
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   236
                /* Just to be sure about the path length until Windows Vista approach.
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   237
                 * [S_FALSE] could not be returned due to [CSIDL_FLAG_DONT_VERIFY] flag and UNICODE version.
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   238
                 */
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   239
                path[MAX_PATH] = 0;
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   240
                u_path = _wcsdup(path);
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   241
            }
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   242
        }
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   243
    }
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   244
    return u_path;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
static boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
haveMMX(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
{
9027
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 7668
diff changeset
   250
    return IsProcessorFeaturePresent(PF_MMX_INSTRUCTIONS_AVAILABLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
static const char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
cpu_isalist(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    SYSTEM_INFO info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    GetSystemInfo(&info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    switch (info.wProcessorArchitecture) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
#ifdef PROCESSOR_ARCHITECTURE_IA64
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    case PROCESSOR_ARCHITECTURE_IA64: return "ia64";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
#ifdef PROCESSOR_ARCHITECTURE_AMD64
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    case PROCESSOR_ARCHITECTURE_AMD64: return "amd64";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    case PROCESSOR_ARCHITECTURE_INTEL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        switch (info.wProcessorLevel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        case 6: return haveMMX()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            ? "pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            : "pentium_pro pentium i486 i386 i86";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        case 5: return haveMMX()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            ? "pentium+mmx pentium i486 i386 i86"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            : "pentium i486 i386 i86";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        case 4: return "i486 i386 i86";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        case 3: return "i386 i86";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
22939
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   280
static boolean
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   281
SetupI18nProps(LCID lcid, char** language, char** script, char** country,
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   282
               char** variant, char** encoding) {
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   283
    /* script */
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   284
    char tmp[SNAMESIZE];
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   285
    *script = malloc(PROPSIZE);
22939
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   286
    if (*script == NULL) {
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   287
        return FALSE;
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   288
    }
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   289
    if (GetLocaleInfo(lcid,
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   290
                      LOCALE_SNAME, tmp, SNAMESIZE) == 0 ||
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   291
        sscanf(tmp, "%*[a-z\\-]%1[A-Z]%[a-z]", *script, &((*script)[1])) == 0 ||
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   292
        strlen(*script) != 4) {
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   293
        (*script)[0] = '\0';
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   294
    }
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   295
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   296
    /* country */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   297
    *country = malloc(PROPSIZE);
22939
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   298
    if (*country == NULL) {
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   299
        return FALSE;
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   300
    }
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   301
    if (GetLocaleInfo(lcid,
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   302
                      LOCALE_SISO3166CTRYNAME, *country, PROPSIZE) == 0 &&
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   303
        GetLocaleInfo(lcid,
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   304
                      LOCALE_SISO3166CTRYNAME2, *country, PROPSIZE) == 0) {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   305
        (*country)[0] = '\0';
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   306
    }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   307
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   308
    /* language */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   309
    *language = malloc(PROPSIZE);
22939
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   310
    if (*language == NULL) {
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   311
        return FALSE;
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   312
    }
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   313
    if (GetLocaleInfo(lcid,
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   314
                      LOCALE_SISO639LANGNAME, *language, PROPSIZE) == 0 &&
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   315
        GetLocaleInfo(lcid,
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   316
                      LOCALE_SISO639LANGNAME2, *language, PROPSIZE) == 0) {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   317
            /* defaults to en_US */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   318
            strcpy(*language, "en");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   319
            strcpy(*country, "US");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   320
        }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   321
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   322
    /* variant */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   323
    *variant = malloc(PROPSIZE);
22939
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   324
    if (*variant == NULL) {
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   325
        return FALSE;
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   326
    }
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   327
    (*variant)[0] = '\0';
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   328
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   329
    /* handling for Norwegian */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   330
    if (strcmp(*language, "nb") == 0) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   331
        strcpy(*language, "no");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   332
        strcpy(*country , "NO");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   333
    } else if (strcmp(*language, "nn") == 0) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   334
        strcpy(*language, "no");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   335
        strcpy(*country , "NO");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   336
        strcpy(*variant, "NY");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   337
    }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   338
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   339
    /* encoding */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   340
    *encoding = getEncodingInternal(lcid);
22939
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   341
    if (*encoding == NULL) {
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   342
        return FALSE;
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   343
    }
fc08f20ea32f 8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending
naoto
parents: 19190
diff changeset
   344
    return TRUE;
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   345
}
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   346
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
java_props_t *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
GetJavaProperties(JNIEnv* env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    static java_props_t sprops = {0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   352
    OSVERSIONINFOEX ver;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   353
15291
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   354
    if (sprops.line_separator) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        return &sprops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /* AWT properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    sprops.awt_toolkit = "sun.awt.windows.WToolkit";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    /* tmp dir */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    {
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   363
        WCHAR tmpdir[MAX_PATH + 1];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        /* we might want to check that this succeed */
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   365
        GetTempPathW(MAX_PATH + 1, tmpdir);
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   366
        sprops.tmp_dir = _wcsdup(tmpdir);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /* Printing properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    sprops.printerJob = "sun.awt.windows.WPrinterJob";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    /* Java2D properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    sprops.graphics_env = "sun.awt.Win32GraphicsEnvironment";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    {    /* This is used only for debugging of font problems. */
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   376
        WCHAR *path = _wgetenv(L"JAVA2D_FONTPATH");
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   377
        sprops.font_dir = (path != NULL) ? _wcsdup(path) : NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    /* OS properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        char buf[100];
1626
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   383
        SYSTEM_INFO si;
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   384
        PGNSI pGNSI;
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   385
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        ver.dwOSVersionInfoSize = sizeof(ver);
49
b25b3ff21b7c 6642034: System.getProperty("os.name") returns Windows Vista on Windows Server 2008 (longhorn)
martin
parents: 2
diff changeset
   387
        GetVersionEx((OSVERSIONINFO *) &ver);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
1626
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   389
        ZeroMemory(&si, sizeof(SYSTEM_INFO));
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   390
        // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise.
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   391
        pGNSI = (PGNSI) GetProcAddress(
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   392
                GetModuleHandle(TEXT("kernel32.dll")),
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   393
                "GetNativeSystemInfo");
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   394
        if(NULL != pGNSI)
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   395
            pGNSI(&si);
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   396
        else
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   397
            GetSystemInfo(&si);
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   398
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
         * From msdn page on OSVERSIONINFOEX, current as of this
49
b25b3ff21b7c 6642034: System.getProperty("os.name") returns Windows Vista on Windows Server 2008 (longhorn)
martin
parents: 2
diff changeset
   401
         * writing, decoding of dwMajorVersion and dwMinorVersion.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
         *  Operating system            dwMajorVersion  dwMinorVersion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
         * ==================           ==============  ==============
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
         * Windows 95                   4               0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
         * Windows 98                   4               10
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
         * Windows ME                   4               90
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
         * Windows 3.51                 3               51
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
         * Windows NT 4.0               4               0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
         * Windows 2000                 5               0
1626
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   412
         * Windows XP 32 bit            5               1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
         * Windows Server 2003 family   5               2
1626
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   414
         * Windows XP 64 bit            5               2
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   415
         *       where ((&ver.wServicePackMinor) + 2) = 1
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   416
         *       and  si.wProcessorArchitecture = 9
3212
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   417
         * Windows Vista family         6               0  (VER_NT_WORKSTATION)
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   418
         * Windows Server 2008          6               0  (!VER_NT_WORKSTATION)
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   419
         * Windows 7                    6               1  (VER_NT_WORKSTATION)
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   420
         * Windows Server 2008 R2       6               1  (!VER_NT_WORKSTATION)
12843
f785258dea60 7170169: (props) System.getProperty("os.name") should return "Windows 8" when run on Windows 8
khazra
parents: 11906
diff changeset
   421
         * Windows 8                    6               2  (VER_NT_WORKSTATION)
12873
e7c4a8144e66 7173645: (props) System.getProperty("os.name") should return "Windows Server 2012" for Windows Server 2012
khazra
parents: 12843
diff changeset
   422
         * Windows Server 2012          6               2  (!VER_NT_WORKSTATION)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
         * This mapping will presumably be augmented as new Windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
         * versions are released.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        switch (ver.dwPlatformId) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        case VER_PLATFORM_WIN32s:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            sprops.os_name = "Windows 3.1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        case VER_PLATFORM_WIN32_WINDOWS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
           if (ver.dwMajorVersion == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                switch (ver.dwMinorVersion) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                case  0: sprops.os_name = "Windows 95";           break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                case 10: sprops.os_name = "Windows 98";           break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                case 90: sprops.os_name = "Windows Me";           break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                default: sprops.os_name = "Windows 9X (unknown)"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                sprops.os_name = "Windows 9X (unknown)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        case VER_PLATFORM_WIN32_NT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            if (ver.dwMajorVersion <= 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                sprops.os_name = "Windows NT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            } else if (ver.dwMajorVersion == 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                switch (ver.dwMinorVersion) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                case  0: sprops.os_name = "Windows 2000";         break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                case  1: sprops.os_name = "Windows XP";           break;
1626
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   450
                case  2:
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   451
                   /*
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   452
                    * From MSDN OSVERSIONINFOEX and SYSTEM_INFO documentation:
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   453
                    *
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   454
                    * "Because the version numbers for Windows Server 2003
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   455
                    * and Windows XP 6u4 bit are identical, you must also test
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   456
                    * whether the wProductType member is VER_NT_WORKSTATION.
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   457
                    * and si.wProcessorArchitecture is
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   458
                    * PROCESSOR_ARCHITECTURE_AMD64 (which is 9)
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   459
                    * If it is, the operating system is Windows XP 64 bit;
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   460
                    * otherwise, it is Windows Server 2003."
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   461
                    */
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   462
                    if(ver.wProductType == VER_NT_WORKSTATION &&
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   463
                       si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) {
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   464
                        sprops.os_name = "Windows XP"; /* 64 bit */
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   465
                    } else {
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   466
                        sprops.os_name = "Windows 2003";
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   467
                    }
e1c6dff266e5 6714428: 'os.name' system property shows wrong value on 64-bit Windows XP
sherman
parents: 715
diff changeset
   468
                    break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                default: sprops.os_name = "Windows NT (unknown)"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            } else if (ver.dwMajorVersion == 6) {
49
b25b3ff21b7c 6642034: System.getProperty("os.name") returns Windows Vista on Windows Server 2008 (longhorn)
martin
parents: 2
diff changeset
   472
                /*
3212
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   473
                 * See table in MSDN OSVERSIONINFOEX documentation.
49
b25b3ff21b7c 6642034: System.getProperty("os.name") returns Windows Vista on Windows Server 2008 (longhorn)
martin
parents: 2
diff changeset
   474
                 */
2424
3663fccf2fc3 6819886: System.getProperty("os.name") reports Vista on Windows 7
alanb
parents: 1626
diff changeset
   475
                if (ver.wProductType == VER_NT_WORKSTATION) {
3663fccf2fc3 6819886: System.getProperty("os.name") reports Vista on Windows 7
alanb
parents: 1626
diff changeset
   476
                    switch (ver.dwMinorVersion) {
3663fccf2fc3 6819886: System.getProperty("os.name") reports Vista on Windows 7
alanb
parents: 1626
diff changeset
   477
                    case  0: sprops.os_name = "Windows Vista";        break;
3663fccf2fc3 6819886: System.getProperty("os.name") reports Vista on Windows 7
alanb
parents: 1626
diff changeset
   478
                    case  1: sprops.os_name = "Windows 7";            break;
12843
f785258dea60 7170169: (props) System.getProperty("os.name") should return "Windows 8" when run on Windows 8
khazra
parents: 11906
diff changeset
   479
                    case  2: sprops.os_name = "Windows 8";            break;
19190
50a4d01485a1 8020191: System.getProperty("os.name") returns "Windows NT (unknown)" on Windows 8.1
uta
parents: 15291
diff changeset
   480
                    case  3: sprops.os_name = "Windows 8.1";          break;
2424
3663fccf2fc3 6819886: System.getProperty("os.name") reports Vista on Windows 7
alanb
parents: 1626
diff changeset
   481
                    default: sprops.os_name = "Windows NT (unknown)";
3663fccf2fc3 6819886: System.getProperty("os.name") reports Vista on Windows 7
alanb
parents: 1626
diff changeset
   482
                    }
3663fccf2fc3 6819886: System.getProperty("os.name") reports Vista on Windows 7
alanb
parents: 1626
diff changeset
   483
                } else {
3212
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   484
                    switch (ver.dwMinorVersion) {
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   485
                    case  0: sprops.os_name = "Windows Server 2008";    break;
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   486
                    case  1: sprops.os_name = "Windows Server 2008 R2"; break;
12873
e7c4a8144e66 7173645: (props) System.getProperty("os.name") should return "Windows Server 2012" for Windows Server 2012
khazra
parents: 12843
diff changeset
   487
                    case  2: sprops.os_name = "Windows Server 2012";    break;
19190
50a4d01485a1 8020191: System.getProperty("os.name") returns "Windows NT (unknown)" on Windows 8.1
uta
parents: 15291
diff changeset
   488
                    case  3: sprops.os_name = "Windows Server 2012 R2"; break;
3212
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   489
                    default: sprops.os_name = "Windows NT (unknown)";
abb0afb64fe6 6843003: Windows Server 2008 R2 system recognition
alanb
parents: 2424
diff changeset
   490
                    }
2424
3663fccf2fc3 6819886: System.getProperty("os.name") reports Vista on Windows 7
alanb
parents: 1626
diff changeset
   491
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                sprops.os_name = "Windows NT (unknown)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            sprops.os_name = "Windows (unknown)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        sprintf(buf, "%d.%d", ver.dwMajorVersion, ver.dwMinorVersion);
6850
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 6489
diff changeset
   501
        sprops.os_version = _strdup(buf);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
#if _M_IA64
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        sprops.os_arch = "ia64";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
#elif _M_AMD64
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        sprops.os_arch = "amd64";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
#elif _X86_
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        sprops.os_arch = "x86";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        sprops.os_arch = "unknown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
6850
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 6489
diff changeset
   512
        sprops.patch_level = _strdup(ver.szCSDVersion);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        sprops.desktop = "windows";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    /* Endianness of platform */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        unsigned int endianTest = 0xff000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        if (((char*)(&endianTest))[0] != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            sprops.cpu_endian = "big";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            sprops.cpu_endian = "little";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    /* CPU ISA list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    sprops.cpu_isalist = cpu_isalist();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * User name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * We try to avoid calling GetUserName as it turns out to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * be surprisingly expensive on NT.  It pulls in an extra
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * 100 K of footprint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    {
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   537
        WCHAR *uname = _wgetenv(L"USERNAME");
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   538
        if (uname != NULL && wcslen(uname) > 0) {
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   539
            sprops.user_name = _wcsdup(uname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        } else {
9027
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 7668
diff changeset
   541
            DWORD buflen = 0;
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 7668
diff changeset
   542
            if (GetUserNameW(NULL, &buflen) == 0 &&
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 7668
diff changeset
   543
                GetLastError() == ERROR_INSUFFICIENT_BUFFER)
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 7668
diff changeset
   544
            {
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 7668
diff changeset
   545
                uname = (WCHAR*)malloc(buflen * sizeof(WCHAR));
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 7668
diff changeset
   546
                if (uname != NULL && GetUserNameW(uname, &buflen) == 0) {
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 7668
diff changeset
   547
                    free(uname);
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 7668
diff changeset
   548
                    uname = NULL;
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 7668
diff changeset
   549
                }
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 7668
diff changeset
   550
            } else {
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 7668
diff changeset
   551
                uname = NULL;
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 7668
diff changeset
   552
            }
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 7668
diff changeset
   553
            sprops.user_name = (uname != NULL) ? uname : L"unknown";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    /*
15291
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   558
     * Home directory
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * The normal result is that for a given user name XXX:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     *     On multi-user NT, user.home gets set to c:\winnt\profiles\XXX.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *     On multi-user Win95, user.home gets set to c:\windows\profiles\XXX.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     *     On single-user Win95, user.home gets set to c:\windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    {
15291
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   566
        WCHAR *homep = getHomeFromShell32();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        if (homep == NULL) {
15291
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   568
            homep = L"C:\\";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
15291
ca60e5764de5 6519127: user.home property not set correctly
uta
parents: 14342
diff changeset
   570
        sprops.user_home = homep;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     *  user.language
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   575
     *  user.script, user.country, user.variant (if user's environment specifies them)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     *  file.encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *  file.encoding.pkg
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
         * query the system for the current system default locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
         * (which is a Windows LCID value),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
         */
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   584
        LCID userDefaultLCID = GetUserDefaultLCID();
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   585
        LCID systemDefaultLCID = GetSystemDefaultLCID();
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   586
        LCID userDefaultUILang = GetUserDefaultUILanguage();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   589
            char * display_encoding;
11906
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   590
            HANDLE hStdOutErr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
10338
ffaa7122547c 7073906: Locale.getDefault() returns wrong Locale for Java SE 7
naoto
parents: 9027
diff changeset
   592
            // Windows UI Language selection list only cares "language"
ffaa7122547c 7073906: Locale.getDefault() returns wrong Locale for Java SE 7
naoto
parents: 9027
diff changeset
   593
            // information of the UI Language. For example, the list
ffaa7122547c 7073906: Locale.getDefault() returns wrong Locale for Java SE 7
naoto
parents: 9027
diff changeset
   594
            // just lists "English" but it actually means "en_US", and
ffaa7122547c 7073906: Locale.getDefault() returns wrong Locale for Java SE 7
naoto
parents: 9027
diff changeset
   595
            // the user cannot select "en_GB" (if exists) in the list.
ffaa7122547c 7073906: Locale.getDefault() returns wrong Locale for Java SE 7
naoto
parents: 9027
diff changeset
   596
            // So, this hack is to use the user LCID region information
ffaa7122547c 7073906: Locale.getDefault() returns wrong Locale for Java SE 7
naoto
parents: 9027
diff changeset
   597
            // for the UI Language, if the "language" portion of those
ffaa7122547c 7073906: Locale.getDefault() returns wrong Locale for Java SE 7
naoto
parents: 9027
diff changeset
   598
            // two locales are the same.
ffaa7122547c 7073906: Locale.getDefault() returns wrong Locale for Java SE 7
naoto
parents: 9027
diff changeset
   599
            if (PRIMARYLANGID(LANGIDFROMLCID(userDefaultLCID)) ==
ffaa7122547c 7073906: Locale.getDefault() returns wrong Locale for Java SE 7
naoto
parents: 9027
diff changeset
   600
                PRIMARYLANGID(LANGIDFROMLCID(userDefaultUILang))) {
ffaa7122547c 7073906: Locale.getDefault() returns wrong Locale for Java SE 7
naoto
parents: 9027
diff changeset
   601
                userDefaultUILang = userDefaultLCID;
ffaa7122547c 7073906: Locale.getDefault() returns wrong Locale for Java SE 7
naoto
parents: 9027
diff changeset
   602
            }
ffaa7122547c 7073906: Locale.getDefault() returns wrong Locale for Java SE 7
naoto
parents: 9027
diff changeset
   603
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   604
            SetupI18nProps(userDefaultUILang,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   605
                           &sprops.language,
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   606
                           &sprops.script,
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   607
                           &sprops.country,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   608
                           &sprops.variant,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   609
                           &display_encoding);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   610
            SetupI18nProps(userDefaultLCID,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   611
                           &sprops.format_language,
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   612
                           &sprops.format_script,
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   613
                           &sprops.format_country,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   614
                           &sprops.format_variant,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   615
                           &sprops.encoding);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   616
            SetupI18nProps(userDefaultUILang,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   617
                           &sprops.display_language,
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   618
                           &sprops.display_script,
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   619
                           &sprops.display_country,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   620
                           &sprops.display_variant,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   621
                           &display_encoding);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   623
            sprops.sun_jnu_encoding = getEncodingInternal(systemDefaultLCID);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   624
            if (LANGIDFROMLCID(userDefaultLCID) == 0x0c04 && ver.dwMajorVersion == 6) {
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   625
                // MS claims "Vista has built-in support for HKSCS-2004.
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   626
                // All of the HKSCS-2004 characters have Unicode 4.1.
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   627
                // PUA code point assignments". But what it really means
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   628
                // is that the HKSCS-2004 is ONLY supported in Unicode.
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   629
                // Test indicates the MS950 in its zh_HK locale is a
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   630
                // "regular" MS950 which does not handle HKSCS-2004 at
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   631
                // all. Set encoding to MS950_HKSCS.
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   632
                sprops.encoding = "MS950_HKSCS";
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   633
                sprops.sun_jnu_encoding = "MS950_HKSCS";
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 3288
diff changeset
   634
            }
11906
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   635
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   636
            hStdOutErr = GetStdHandle(STD_OUTPUT_HANDLE);
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   637
            if (hStdOutErr != INVALID_HANDLE_VALUE &&
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   638
                GetFileType(hStdOutErr) == FILE_TYPE_CHAR) {
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   639
                sprops.sun_stdout_encoding = getConsoleEncoding();
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   640
            }
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   641
            hStdOutErr = GetStdHandle(STD_ERROR_HANDLE);
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   642
            if (hStdOutErr != INVALID_HANDLE_VALUE &&
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   643
                GetFileType(hStdOutErr) == FILE_TYPE_CHAR) {
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   644
                if (sprops.sun_stdout_encoding != NULL)
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   645
                    sprops.sun_stderr_encoding = sprops.sun_stdout_encoding;
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   646
                else
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   647
                    sprops.sun_stderr_encoding = getConsoleEncoding();
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 10338
diff changeset
   648
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    sprops.unicode_encoding = "UnicodeLittle";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    /* User TIMEZONE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
         * We defer setting up timezone until it's actually necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
         * Refer to TimeZone.getDefault(). However, the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
         * property is necessary to be able to be set by the command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
         * line interface -D. Here temporarily set a null string to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
         * timezone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        sprops.timezone = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    /* Current directory */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    {
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   667
        WCHAR buf[MAX_PATH];
9027
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 7668
diff changeset
   668
        if (GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR), buf) != 0)
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 7668
diff changeset
   669
            sprops.user_dir = _wcsdup(buf);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    sprops.file_separator = "\\";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    sprops.path_separator = ";";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    sprops.line_separator = "\r\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    return &sprops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
}
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   678
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   679
jstring
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   680
GetStringPlatform(JNIEnv *env, nchar* wcstr)
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   681
{
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   682
    return (*env)->NewString(env, wcstr, wcslen(wcstr));
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   683
}