jdk/src/solaris/native/java/lang/java_props_md.c
author lana
Tue, 07 Aug 2012 20:23:41 -0700
changeset 13413 1ed9a01478b4
parent 13405 69267890f7d9
parent 13349 b12dcd2c3e07
child 13414 1e161ce0b69e
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
     2
 * Copyright (c) 1998, 2011, 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
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
    26
#if defined(__linux__) || defined(_ALLBSD_SOURCE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <ctype.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <pwd.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <locale.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#ifndef ARCHPROPNAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#error "The macro ARCHPROPNAME has not been defined"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <sys/utsname.h>        /* For os_name and os_version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include <langinfo.h>           /* For nl_langinfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include <unistd.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include <sys/param.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include <time.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include <errno.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
    45
#ifdef MACOSX
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
    46
#include "java_props_macosx.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
    47
#endif
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
    48
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
    49
#if defined(_ALLBSD_SOURCE)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
    50
#if !defined(P_tmpdir)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
    51
#include <paths.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
    52
#define P_tmpdir _PATH_VARTMP
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
    53
#endif
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
    54
#endif
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
    55
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#include "locale_str.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#include "java_props.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
    59
#if !defined(_ALLBSD_SOURCE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#ifdef __linux__
6850
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 6489
diff changeset
    61
  #ifndef CODESET
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 6489
diff changeset
    62
  #define CODESET _NL_CTYPE_CODESET_NAME
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 6489
diff changeset
    63
  #endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#ifdef ALT_CODESET_KEY
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#define CODESET ALT_CODESET_KEY
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#endif
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
    69
#endif /* !_ALLBSD_SOURCE */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
    71
#ifdef JAVASE_EMBEDDED
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
    72
#include <dlfcn.h>
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
    73
#include <sys/stat.h>
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
    74
#endif
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
    75
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
/* Take an array of string pairs (map of key->value) and a string (key).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * Examine each pair in the map to see if the first string (key) matches the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * string.  If so, store the second string of the pair (value) in the value and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * return 1.  Otherwise do nothing and return 0.  The end of the map is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * indicated by an empty string at the start of a pair (key of "").
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
mapLookup(char* map[], const char* key, char** value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    for (i = 0; strcmp(map[i], ""); i += 2){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if (!strcmp(key, map[i])){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            *value = map[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
/* This function sets an environment variable using envstring.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * The format of envstring is "name=value".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * If the name has already existed, it will append value to the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
setPathEnvironment(char *envstring)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    char name[20], *value, *current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    value = strchr(envstring, '='); /* locate name and value separator */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    if (! value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return; /* not a valid environment setting */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /* copy first part as environment name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    strncpy(name, envstring, value - envstring);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    name[value-envstring] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    value++; /* set value point to value of the envstring */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    current = getenv(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    if (current) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (! strstr(current, value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            /* value is not found in current environment, append it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            char *temp = malloc(strlen(envstring) + strlen(current) + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        strcpy(temp, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        strcat(temp, "=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        strcat(temp, current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        strcat(temp, ":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        strcat(temp, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        putenv(temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        /* else the value has already been set, do nothing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        /* environment variable is not found */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        putenv(envstring);
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
#ifndef P_tmpdir
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
#define P_tmpdir "/var/tmp"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
13405
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   138
static int ParseLocale(JNIEnv* env, int cat, char ** std_language, char ** std_script,
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   139
                       char ** std_country, char ** std_variant, char ** std_encoding) {
13405
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   140
    char *temp = NULL;
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   141
    char *language = NULL, *country = NULL, *variant = NULL,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   142
         *encoding = NULL;
13405
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   143
    char *p, *encoding_variant;
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   144
    char *lc;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   145
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   146
    /* Query the locale set for the category */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   147
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   148
#ifdef MACOSX
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   149
    lc = setupMacOSXLocale(cat); // malloc'd memory, need to free
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   150
#else
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   151
    lc = setlocale(cat, NULL);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   152
#endif
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   153
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   154
#ifndef __linux__
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   155
    if (lc == NULL) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   156
        return 0;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   157
    }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   158
13405
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   159
    temp = malloc(strlen(lc) + 1);
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   160
    if (temp == NULL) {
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   161
        JNU_ThrowOutOfMemoryError(env, NULL);
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   162
        return 0;
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   163
    }
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   164
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   165
    if (cat == LC_CTYPE) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   166
        /*
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   167
         * Workaround for Solaris bug 4201684: Xlib doesn't like @euro
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   168
         * locales. Since we don't depend on the libc @euro behavior,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   169
         * we just remove the qualifier.
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   170
         * On Linux, the bug doesn't occur; on the other hand, @euro
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   171
         * is needed there because it's a shortcut that also determines
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   172
         * the encoding - without it, we wouldn't get ISO-8859-15.
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   173
         * Therefore, this code section is Solaris-specific.
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   174
         */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   175
        lc = strdup(lc);    /* keep a copy, setlocale trashes original. */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   176
        strcpy(temp, lc);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   177
        p = strstr(temp, "@euro");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   178
        if (p != NULL) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   179
            *p = '\0';
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   180
            setlocale(LC_ALL, temp);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   181
        }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   182
    }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   183
#else
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   184
    if (lc == NULL || !strcmp(lc, "C") || !strcmp(lc, "POSIX")) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   185
        lc = "en_US";
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   186
    }
13405
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   187
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   188
    temp = malloc(strlen(lc) + 1);
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   189
    if (temp == NULL) {
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   190
        JNU_ThrowOutOfMemoryError(env, NULL);
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   191
        return 0;
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   192
    }
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   193
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   194
#endif
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   195
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   196
    /*
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   197
     * locale string format in Solaris is
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   198
     * <language name>_<country name>.<encoding name>@<variant name>
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   199
     * <country name>, <encoding name>, and <variant name> are optional.
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   200
     */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   201
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   202
    strcpy(temp, lc);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   203
#ifdef MACOSX
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   204
    free(lc); // malloced memory
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   205
#endif
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   206
    /* Parse the language, country, encoding, and variant from the
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   207
     * locale.  Any of the elements may be missing, but they must occur
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   208
     * in the order language_country.encoding@variant, and must be
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   209
     * preceded by their delimiter (except for language).
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   210
     *
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   211
     * If the locale name (without .encoding@variant, if any) matches
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   212
     * any of the names in the locale_aliases list, map it to the
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   213
     * corresponding full locale name.  Most of the entries in the
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   214
     * locale_aliases list are locales that include a language name but
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   215
     * no country name, and this facility is used to map each language
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   216
     * to a default country if that's possible.  It's also used to map
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   217
     * the Solaris locale aliases to their proper Java locale IDs.
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   218
     */
13405
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   219
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   220
    encoding_variant = malloc(strlen(temp)+1);
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   221
    if (encoding_variant == NULL) {
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   222
        JNU_ThrowOutOfMemoryError(env, NULL);
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   223
        return 0;
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   224
    }
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   225
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   226
    if ((p = strchr(temp, '.')) != NULL) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   227
        strcpy(encoding_variant, p); /* Copy the leading '.' */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   228
        *p = '\0';
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   229
    } else if ((p = strchr(temp, '@')) != NULL) {
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   230
        strcpy(encoding_variant, p); /* Copy the leading '@' */
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   231
        *p = '\0';
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   232
    } else {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   233
        *encoding_variant = '\0';
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   234
    }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   235
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   236
    if (mapLookup(locale_aliases, temp, &p)) {
13405
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   237
        temp = realloc(temp, strlen(p)+1);
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   238
        if (temp == NULL) {
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   239
            JNU_ThrowOutOfMemoryError(env, NULL);
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   240
            return 0;
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   241
        }
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   242
        strcpy(temp, p);
13405
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   243
        encoding_variant = realloc(encoding_variant, strlen(temp)+1);
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   244
        if (encoding_variant == NULL) {
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   245
            JNU_ThrowOutOfMemoryError(env, NULL);
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   246
            return 0;
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   247
        }
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   248
        // check the "encoding_variant" again, if any.
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   249
        if ((p = strchr(temp, '.')) != NULL) {
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   250
            strcpy(encoding_variant, p); /* Copy the leading '.' */
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   251
            *p = '\0';
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   252
        } else if ((p = strchr(temp, '@')) != NULL) {
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   253
            strcpy(encoding_variant, p); /* Copy the leading '@' */
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   254
            *p = '\0';
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   255
        }
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   256
    }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   257
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   258
    language = temp;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   259
    if ((country = strchr(temp, '_')) != NULL) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   260
        *country++ = '\0';
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   261
    }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   262
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   263
    p = encoding_variant;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   264
    if ((encoding = strchr(p, '.')) != NULL) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   265
        p[encoding++ - p] = '\0';
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   266
        p = encoding;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   267
    }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   268
    if ((variant = strchr(p, '@')) != NULL) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   269
        p[variant++ - p] = '\0';
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   270
    }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   271
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   272
    /* Normalize the language name */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   273
    if (std_language != NULL) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   274
        *std_language = "en";
7248
6a95f692e203 6997999: Remove duplicated entries from ISO language/country code tables
naoto
parents: 7018
diff changeset
   275
        if (language != NULL && mapLookup(language_names, language, std_language) == 0) {
6a95f692e203 6997999: Remove duplicated entries from ISO language/country code tables
naoto
parents: 7018
diff changeset
   276
            *std_language = malloc(strlen(language)+1);
6a95f692e203 6997999: Remove duplicated entries from ISO language/country code tables
naoto
parents: 7018
diff changeset
   277
            strcpy(*std_language, language);
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   278
        }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   279
    }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   280
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   281
    /* Normalize the country name */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   282
    if (std_country != NULL && country != NULL) {
7248
6a95f692e203 6997999: Remove duplicated entries from ISO language/country code tables
naoto
parents: 7018
diff changeset
   283
        if (mapLookup(country_names, country, std_country) == 0) {
6a95f692e203 6997999: Remove duplicated entries from ISO language/country code tables
naoto
parents: 7018
diff changeset
   284
            *std_country = malloc(strlen(country)+1);
6a95f692e203 6997999: Remove duplicated entries from ISO language/country code tables
naoto
parents: 7018
diff changeset
   285
            strcpy(*std_country, country);
6a95f692e203 6997999: Remove duplicated entries from ISO language/country code tables
naoto
parents: 7018
diff changeset
   286
        }
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   287
    }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   288
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   289
    /* Normalize the script and variant name.  Note that we only use
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   290
     * variants listed in the mapping array; others are ignored.
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   291
     */
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   292
    if (variant != NULL) {
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   293
        if (std_script != NULL) {
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   294
            mapLookup(script_names, variant, std_script);
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   295
        }
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   296
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   297
        if (std_variant != NULL) {
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   298
            mapLookup(variant_names, variant, std_variant);
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   299
        }
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   300
    }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   301
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   302
    /* Normalize the encoding name.  Note that we IGNORE the string
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   303
     * 'encoding' extracted from the locale name above.  Instead, we use the
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   304
     * more reliable method of calling nl_langinfo(CODESET).  This function
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   305
     * returns an empty string if no encoding is set for the given locale
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   306
     * (e.g., the C or POSIX locales); we use the default ISO 8859-1
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   307
     * converter for such locales.
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   308
     */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   309
    if (std_encoding != NULL) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   310
        /* OK, not so reliable - nl_langinfo() gives wrong answers on
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   311
         * Euro locales, in particular. */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   312
        if (strcmp(p, "ISO8859-15") == 0)
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   313
            p = "ISO8859-15";
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   314
        else
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   315
            p = nl_langinfo(CODESET);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   316
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   317
        /* Convert the bare "646" used on Solaris to a proper IANA name */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   318
        if (strcmp(p, "646") == 0)
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   319
            p = "ISO646-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
        /* return same result nl_langinfo would return for en_UK,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   322
         * in order to use optimizations. */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   323
        *std_encoding = (*p != '\0') ? p : "ISO8859-1";
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   324
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   325
#ifdef __linux__
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   326
        /*
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   327
         * Remap the encoding string to a different value for japanese
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   328
         * locales on linux so that customized converters are used instead
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   329
         * of the default converter for "EUC-JP". The customized converters
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   330
         * omit support for the JIS0212 encoding which is not supported by
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   331
         * the variant of "EUC-JP" encoding used on linux
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   332
         */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   333
        if (strcmp(p, "EUC-JP") == 0) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   334
            *std_encoding = "EUC-JP-LINUX";
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   335
        }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   336
#else
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   337
        if (strcmp(p,"eucJP") == 0) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   338
            /* For Solaris use customized vendor defined character
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   339
             * customized EUC-JP converter
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   340
             */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   341
            *std_encoding = "eucJP-open";
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   342
        } else if (strcmp(p, "Big5") == 0 || strcmp(p, "BIG5") == 0) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   343
            /*
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   344
             * Remap the encoding string to Big5_Solaris which augments
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   345
             * the default converter for Solaris Big5 locales to include
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   346
             * seven additional ideographic characters beyond those included
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   347
             * in the Java "Big5" converter.
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   348
             */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   349
            *std_encoding = "Big5_Solaris";
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   350
        } else if (strcmp(p, "Big5-HKSCS") == 0) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   351
            /*
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   352
             * Solaris uses HKSCS2001
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   353
             */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   354
            *std_encoding = "Big5-HKSCS-2001";
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   355
        }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   356
#endif
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   357
    }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   358
13405
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   359
    free(temp);
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   360
    free(encoding_variant);
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   361
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   362
    return 1;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   363
}
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   364
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   365
#ifdef JAVASE_EMBEDDED
11665
98dad53a8ba1 7110002: Rename xawt/libmawt.so and headless/libmawt.so so they can be colocated with libawt
chegar
parents: 9002
diff changeset
   366
/* Determine the default embedded toolkit based on whether libawt_xawt
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   367
 * exists in the JRE. This can still be overridden by -Dawt.toolkit=XXX
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   368
 */
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   369
static char* getEmbeddedToolkit() {
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   370
    Dl_info dlinfo;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   371
    char buf[MAXPATHLEN];
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   372
    int32_t len;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   373
    char *p;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   374
    struct stat statbuf;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   375
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   376
    /* Get address of this library and the directory containing it. */
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   377
    dladdr((void *)getEmbeddedToolkit, &dlinfo);
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   378
    realpath((char *)dlinfo.dli_fname, buf);
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   379
    len = strlen(buf);
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   380
    p = strrchr(buf, '/');
11665
98dad53a8ba1 7110002: Rename xawt/libmawt.so and headless/libmawt.so so they can be colocated with libawt
chegar
parents: 9002
diff changeset
   381
    /* Default AWT Toolkit on Linux and Solaris is XAWT (libawt_xawt.so). */
98dad53a8ba1 7110002: Rename xawt/libmawt.so and headless/libmawt.so so they can be colocated with libawt
chegar
parents: 9002
diff changeset
   382
    strncpy(p, "/libawt_xawt.so", MAXPATHLEN-len-1);
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   383
    /* Check if it exists */
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   384
    if (stat(buf, &statbuf) == -1 && errno == ENOENT) {
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   385
        /* No - this is a reduced-headless-jre so use special HToolkit */
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   386
        return "sun.awt.HToolkit";
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   387
    }
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   388
    else {
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   389
        /* Yes - this is a headful JRE so fallback to SE defaults */
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   390
        return NULL;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   391
    }
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   392
}
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   393
#endif
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   394
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
/* This function gets called very early, before VM_CALLS are setup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
 * Do not use any of the VM_CALLS entries!!!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
java_props_t *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
GetJavaProperties(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
{
6850
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 6489
diff changeset
   401
    static java_props_t sprops;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    char *v; /* tmp var */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    if (sprops.user_dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        return &sprops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    /* tmp dir */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    sprops.tmp_dir = P_tmpdir;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   410
#ifdef MACOSX
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   411
    /* darwin has a per-user temp dir */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   412
    static char tmp_path[PATH_MAX];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   413
    int pathSize = confstr(_CS_DARWIN_USER_TEMP_DIR, tmp_path, PATH_MAX);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   414
    if (pathSize > 0 && pathSize <= PATH_MAX) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   415
        sprops.tmp_dir = tmp_path;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   416
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   417
#endif /* MACOSX */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    /* Printing properties */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   420
#ifdef MACOSX
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   421
    sprops.printerJob = "sun.lwawt.macosx.CPrinterJob";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   422
#else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    sprops.printerJob = "sun.print.PSPrinterJob";
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   424
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    /* patches/service packs installed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    sprops.patch_level = "unknown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    /* Java 2D properties */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   430
#ifdef MACOSX
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   431
    PreferredToolkit prefToolkit = getPreferredToolkit();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   432
    switch (prefToolkit) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   433
        case CToolkit:
13349
b12dcd2c3e07 7181027: [macosx] Unable to use headless mode
leonidr
parents: 12818
diff changeset
   434
        case HToolkit:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   435
            sprops.graphics_env = "sun.awt.CGraphicsEnvironment";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   436
            break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   437
        case XToolkit:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   438
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    sprops.graphics_env = "sun.awt.X11GraphicsEnvironment";
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   440
#ifdef MACOSX
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   441
            break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   442
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   443
#endif
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   444
    /* AWT properties */
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   445
#ifdef JAVASE_EMBEDDED
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   446
    sprops.awt_toolkit = getEmbeddedToolkit();
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   447
    if (sprops.awt_toolkit == NULL) // default as below
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   448
#endif
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   449
#ifdef MACOSX
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   450
        switch (prefToolkit) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   451
            case CToolkit:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   452
                sprops.awt_toolkit = "sun.lwawt.macosx.LWCToolkit";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   453
                break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   454
            case XToolkit:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   455
#endif
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7668
diff changeset
   456
    sprops.awt_toolkit = "sun.awt.X11.XToolkit";
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   457
#ifdef MACOSX
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   458
                break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   459
            default:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   460
                sprops.awt_toolkit = "sun.awt.HToolkit";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   461
                break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   462
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   463
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    /* This is used only for debugging of font problems. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    v = getenv("JAVA2D_FONTPATH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    sprops.font_dir = v ? v : NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
#ifdef SI_ISALIST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    /* supported instruction sets */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        char list[258];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        sysinfo(SI_ISALIST, list, sizeof(list));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        sprops.cpu_isalist = strdup(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    sprops.cpu_isalist = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /* endianness of platform */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        unsigned int endianTest = 0xff000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        if (((char*)(&endianTest))[0] != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            sprops.cpu_endian = "big";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            sprops.cpu_endian = "little";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    /* os properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   491
#ifdef MACOSX
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   492
        setOSNameAndVersion(&sprops);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   493
#else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        struct utsname name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        uname(&name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        sprops.os_name = strdup(name.sysname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        sprops.os_version = strdup(name.release);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   498
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        sprops.os_arch = ARCHPROPNAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        if (getenv("GNOME_DESKTOP_SESSION_ID") != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            sprops.desktop = "gnome";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            sprops.desktop = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /* Determine the language, country, variant, and encoding from the host,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * and store these in the user.language, user.country, user.variant and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * file.encoding system properties. */
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   513
    setlocale(LC_ALL, "");
13405
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   514
    if (ParseLocale(env, LC_CTYPE,
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   515
                    &(sprops.format_language),
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   516
                    &(sprops.format_script),
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   517
                    &(sprops.format_country),
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   518
                    &(sprops.format_variant),
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   519
                    &(sprops.encoding))) {
13405
69267890f7d9 6844255: Potential stack corruption in GetJavaProperties
omajid
parents: 12818
diff changeset
   520
        ParseLocale(env, LC_MESSAGES,
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   521
                    &(sprops.language),
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   522
                    &(sprops.script),
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   523
                    &(sprops.country),
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   524
                    &(sprops.variant),
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   525
                    NULL);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   526
    } else {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   527
        sprops.language = "en";
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   528
        sprops.encoding = "ISO8859-1";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    }
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   530
    sprops.display_language = sprops.language;
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6489
diff changeset
   531
    sprops.display_script = sprops.script;
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   532
    sprops.display_country = sprops.country;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   533
    sprops.display_variant = sprops.variant;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   534
    sprops.sun_jnu_encoding = sprops.encoding;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   536
#ifdef _ALLBSD_SOURCE
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   537
#if BYTE_ORDER == _LITTLE_ENDIAN
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   538
     sprops.unicode_encoding = "UnicodeLittle";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   539
 #else
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   540
     sprops.unicode_encoding = "UnicodeBig";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   541
 #endif
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   542
#else /* !_ALLBSD_SOURCE */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
#if __BYTE_ORDER == __LITTLE_ENDIAN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    sprops.unicode_encoding = "UnicodeLittle";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    sprops.unicode_encoding = "UnicodeBig";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    sprops.unicode_encoding = "UnicodeBig";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
#endif
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   552
#endif /* _ALLBSD_SOURCE */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    /* user properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        struct passwd *pwent = getpwuid(getuid());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        sprops.user_name = pwent ? strdup(pwent->pw_name) : "?";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        sprops.user_home = pwent ? strdup(pwent->pw_dir) : "?";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    /* User TIMEZONE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
         * We defer setting up timezone until it's actually necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
         * Refer to TimeZone.getDefault(). However, the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
         * property is necessary to be able to be set by the command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
         * line interface -D. Here temporarily set a null string to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
         * timezone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        tzset();        /* for compatibility */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        sprops.timezone = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    /* Current directory */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        char buf[MAXPATHLEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        errno = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        if (getcwd(buf, sizeof(buf))  == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            JNU_ThrowByName(env, "java/lang/Error",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
             "Properties init: Could not determine current working directory.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            sprops.user_dir = strdup(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    sprops.file_separator = "/";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    sprops.path_separator = ":";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    sprops.line_separator = "\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   589
#if !defined(_ALLBSD_SOURCE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    /* Append CDE message and resource search path to NLSPATH and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * XFILESEARCHPATH, in order to pick localized message for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * FileSelectionDialog window (Bug 4173641).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    setPathEnvironment("NLSPATH=/usr/dt/lib/nls/msg/%L/%N.cat");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    setPathEnvironment("XFILESEARCHPATH=/usr/dt/app-defaults/%L/Dt");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   596
#endif
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   597
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   598
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   599
#ifdef MACOSX
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   600
    setProxyProperties(&sprops);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11665
diff changeset
   601
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    return &sprops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
}
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   605
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   606
jstring
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   607
GetStringPlatform(JNIEnv *env, nchar* cstr)
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   608
{
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   609
    return JNU_NewStringPlatform(env, cstr);
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   610
}