jdk/src/share/native/java/lang/System.c
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 7018 154795ed10de
child 9036 bb5e161d5bb3
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 7018
diff changeset
     2
 * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "jvm.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "java_props.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "java_lang_System.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#define OBJ "Ljava/lang/Object;"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/* Only register the performance-critical methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
static JNINativeMethod methods[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    {"currentTimeMillis", "()J",              (void *)&JVM_CurrentTimeMillis},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    {"nanoTime",          "()J",              (void *)&JVM_NanoTime},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    {"arraycopy",     "(" OBJ "I" OBJ "II)V", (void *)&JVM_ArrayCopy},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#undef OBJ
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
Java_java_lang_System_registerNatives(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    (*env)->RegisterNatives(env, cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                            methods, sizeof(methods)/sizeof(methods[0]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
Java_java_lang_System_identityHashCode(JNIEnv *env, jobject this, jobject x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    return JVM_IHashCode(env, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
#define PUTPROP(props, key, val) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    if (1) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        jstring jkey = (*env)->NewStringUTF(env, key); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        jstring jval = (*env)->NewStringUTF(env, val); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        jobject r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        if ((*env)->ExceptionOccurred(env)) return NULL; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        (*env)->DeleteLocalRef(env, jkey); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        (*env)->DeleteLocalRef(env, jval); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        (*env)->DeleteLocalRef(env, r); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    } else ((void) 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 715
diff changeset
    70
/*  "key" is a char type string with only ASCII character in it.
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 715
diff changeset
    71
    "val" is a nchar (typedefed in java_props.h) type string  */
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 715
diff changeset
    72
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 715
diff changeset
    73
#define PUTPROP_ForPlatformNString(props, key, val) \
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    if (1) { \
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 715
diff changeset
    75
        jstring jkey = (*env)->NewStringUTF(env, key);  \
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 715
diff changeset
    76
        jstring jval = GetStringPlatform(env, val); \
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        jobject r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        if ((*env)->ExceptionOccurred(env)) return NULL; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        (*env)->DeleteLocalRef(env, jkey); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        (*env)->DeleteLocalRef(env, jval); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        (*env)->DeleteLocalRef(env, r); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    } else ((void) 0)
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    83
#define REMOVEPROP(props, key) \
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    84
    if (1) { \
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    85
        jstring jkey = JNU_NewStringPlatform(env, key); \
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    86
        jobject r = (*env)->CallObjectMethod(env, props, removeID, jkey); \
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    87
        if ((*env)->ExceptionOccurred(env)) return NULL; \
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    88
        (*env)->DeleteLocalRef(env, jkey); \
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    89
        (*env)->DeleteLocalRef(env, r); \
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    90
    } else ((void) 0)
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    91
#define GETPROP(props, key, jret) \
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    92
    if (1) { \
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    93
        jstring jkey = JNU_NewStringPlatform(env, key); \
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    94
        jret = (*env)->CallObjectMethod(env, props, getPropID, jkey); \
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    95
        if ((*env)->ExceptionOccurred(env)) return NULL; \
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    96
        (*env)->DeleteLocalRef(env, jkey); \
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
    97
    } else ((void) 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
#ifndef VENDOR /* Third party may overwrite this. */
6676
c8629a8bbd7d 6946527: rebranding system properties per Oracle Requirements (vendor)
ohair
parents: 5506
diff changeset
   100
#define VENDOR "Oracle Corporation"
c8629a8bbd7d 6946527: rebranding system properties per Oracle Requirements (vendor)
ohair
parents: 5506
diff changeset
   101
#define VENDOR_URL "http://java.oracle.com/"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
#define VENDOR_URL_BUG "http://java.sun.com/cgi-bin/bugreport.cgi"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
689
10d8df51c03a 6706299: System property java.class.version should be 51 for jdk7
sherman
parents: 2
diff changeset
   105
#define JAVA_MAX_SUPPORTED_VERSION 51
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
#define JAVA_MAX_SUPPORTED_MINOR_VERSION 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
6676
c8629a8bbd7d 6946527: rebranding system properties per Oracle Requirements (vendor)
ohair
parents: 5506
diff changeset
   108
#ifdef JAVA_SPECIFICATION_VENDOR /* Third party may NOT overwrite this. */
c8629a8bbd7d 6946527: rebranding system properties per Oracle Requirements (vendor)
ohair
parents: 5506
diff changeset
   109
  #error "ERROR: No override of JAVA_SPECIFICATION_VENDOR is allowed"
c8629a8bbd7d 6946527: rebranding system properties per Oracle Requirements (vendor)
ohair
parents: 5506
diff changeset
   110
#else
c8629a8bbd7d 6946527: rebranding system properties per Oracle Requirements (vendor)
ohair
parents: 5506
diff changeset
   111
  #define JAVA_SPECIFICATION_VENDOR "Oracle Corporation"
6850
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 6683
diff changeset
   112
#endif
6683
lana
parents: 6676 6489
diff changeset
   113
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   114
static int fmtdefault; // boolean value
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   115
jobject fillI18nProps(JNIEnv *env, jobject props, char *baseKey,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   116
                      char *platformDispVal, char *platformFmtVal,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   117
                      jmethodID putID, jmethodID getPropID) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   118
    jstring jVMBaseVal = NULL;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   119
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   120
    GETPROP(props, baseKey, jVMBaseVal);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   121
    if (jVMBaseVal) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   122
        // user specified the base property.  there's nothing to do here.
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   123
        (*env)->DeleteLocalRef(env, jVMBaseVal);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   124
    } else {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   125
        char buf[64];
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   126
        jstring jVMVal = NULL;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   127
        const char *baseVal = "";
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   128
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   129
        /* user.xxx base property */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   130
        if (fmtdefault) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   131
            if (platformFmtVal) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   132
                PUTPROP(props, baseKey, platformFmtVal);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   133
                baseVal = platformFmtVal;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   134
            }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   135
        } else {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   136
            if (platformDispVal) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   137
                PUTPROP(props, baseKey, platformDispVal);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   138
                baseVal = platformDispVal;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   139
            }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   140
        }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   141
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   142
        /* user.xxx.display property */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   143
        jio_snprintf(buf, sizeof(buf), "%s.display", baseKey);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   144
        GETPROP(props, buf, jVMVal);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   145
        if (jVMVal == NULL) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   146
            if (platformDispVal && (strcmp(baseVal, platformDispVal) != 0)) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   147
                PUTPROP(props, buf, platformDispVal);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   148
            }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   149
        } else {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   150
            (*env)->DeleteLocalRef(env, jVMVal);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   151
        }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   152
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   153
        /* user.xxx.format property */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   154
        jio_snprintf(buf, sizeof(buf), "%s.format", baseKey);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   155
        GETPROP(props, buf, jVMVal);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   156
        if (jVMVal == NULL) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   157
            if (platformFmtVal && (strcmp(baseVal, platformFmtVal) != 0)) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   158
                PUTPROP(props, buf, platformFmtVal);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   159
            }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   160
        } else {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   161
            (*env)->DeleteLocalRef(env, jVMVal);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   162
        }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   163
    }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   164
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   165
    return NULL;
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
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
JNIEXPORT jobject JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    char buf[128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    java_props_t *sprops = GetJavaProperties(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    jmethodID putID = (*env)->GetMethodID(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                                          (*env)->GetObjectClass(env, props),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                          "put",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   177
    jmethodID removeID = (*env)->GetMethodID(env,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   178
                                          (*env)->GetObjectClass(env, props),
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   179
                                          "remove",
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   180
            "(Ljava/lang/Object;)Ljava/lang/Object;");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   181
    jmethodID getPropID = (*env)->GetMethodID(env,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   182
                                          (*env)->GetObjectClass(env, props),
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   183
                                          "getProperty",
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   184
            "(Ljava/lang/String;)Ljava/lang/String;");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   185
    jobject ret = NULL;
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   186
    jstring jVMVal = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    if (sprops == NULL || putID == NULL ) return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    PUTPROP(props, "java.specification.version",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            JDK_MAJOR_VERSION "." JDK_MINOR_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    PUTPROP(props, "java.specification.name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            "Java Platform API Specification");
6676
c8629a8bbd7d 6946527: rebranding system properties per Oracle Requirements (vendor)
ohair
parents: 5506
diff changeset
   194
    PUTPROP(props, "java.specification.vendor",
c8629a8bbd7d 6946527: rebranding system properties per Oracle Requirements (vendor)
ohair
parents: 5506
diff changeset
   195
            JAVA_SPECIFICATION_VENDOR);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    PUTPROP(props, "java.version", RELEASE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    PUTPROP(props, "java.vendor", VENDOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    PUTPROP(props, "java.vendor.url", VENDOR_URL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    PUTPROP(props, "java.vendor.url.bug", VENDOR_URL_BUG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    jio_snprintf(buf, sizeof(buf), "%d.%d", JAVA_MAX_SUPPORTED_VERSION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                                            JAVA_MAX_SUPPORTED_MINOR_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    PUTPROP(props, "java.class.version", buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    if (sprops->awt_toolkit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        PUTPROP(props, "awt.toolkit", sprops->awt_toolkit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /* os properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    PUTPROP(props, "os.name", sprops->os_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    PUTPROP(props, "os.version", sprops->os_version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    PUTPROP(props, "os.arch", sprops->os_arch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /* file system properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    PUTPROP(props, "file.separator", sprops->file_separator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    PUTPROP(props, "path.separator", sprops->path_separator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    PUTPROP(props, "line.separator", sprops->line_separator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *  user.language
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6683
diff changeset
   222
     *  user.script, user.country, user.variant (if user's environment specifies them)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *  file.encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *  file.encoding.pkg
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    PUTPROP(props, "user.language", sprops->language);
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6683
diff changeset
   227
    if (sprops->script) {
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6683
diff changeset
   228
        PUTPROP(props, "user.script", sprops->script);
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6683
diff changeset
   229
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    if (sprops->country) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        PUTPROP(props, "user.country", sprops->country);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    if (sprops->variant) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        PUTPROP(props, "user.variant", sprops->variant);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    PUTPROP(props, "file.encoding", sprops->encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    PUTPROP(props, "sun.jnu.encoding", sprops->sun_jnu_encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    PUTPROP(props, "file.encoding.pkg", "sun.io");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /* unicode_encoding specifies the default endianness */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    PUTPROP(props, "sun.io.unicode.encoding", sprops->unicode_encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    PUTPROP(props, "sun.cpu.isalist",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            (sprops->cpu_isalist ? sprops->cpu_isalist : ""));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    PUTPROP(props, "sun.cpu.endian",  sprops->cpu_endian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 715
diff changeset
   245
    /* !!! DO NOT call PUTPROP_ForPlatformNString before this line !!!
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * !!! I18n properties have not been set up yet !!!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /* Printing properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /* Note: java.awt.printerjob is an implementation private property which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * just happens to have a java.* name because it is referenced in
6676
c8629a8bbd7d 6946527: rebranding system properties per Oracle Requirements (vendor)
ohair
parents: 5506
diff changeset
   252
     * a java.awt class. It is the mechanism by which the implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * finds the appropriate class in the JRE for the platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * It is explicitly not designed to be overridden by clients as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * a way of replacing the implementation class, and in any case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * the mechanism by which the class is loaded is constrained to only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * find and load classes that are part of the JRE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * This property may be removed if that mechanism is redesigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    PUTPROP(props, "java.awt.printerjob", sprops->printerJob);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /* data model */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    if (sizeof(sprops) == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        sprops->data_model = "32";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    } else if (sizeof(sprops) == 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        sprops->data_model = "64";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        sprops->data_model = "unknown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    PUTPROP(props, "sun.arch.data.model",  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    sprops->data_model);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /* patch level */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    PUTPROP(props, "sun.os.patch.level",  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    sprops->patch_level);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /* Java2D properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    /* Note: java.awt.graphicsenv is an implementation private property which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * just happens to have a java.* name because it is referenced in
6676
c8629a8bbd7d 6946527: rebranding system properties per Oracle Requirements (vendor)
ohair
parents: 5506
diff changeset
   280
     * a java.awt class. It is the mechanism by which the implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * finds the appropriate class in the JRE for the platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * It is explicitly not designed to be overridden by clients as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * a way of replacing the implementation class, and in any case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * the mechanism by which the class is loaded is constrained to only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * find and load classes that are part of the JRE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * This property may be removed if that mechanism is redesigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    PUTPROP(props, "java.awt.graphicsenv", sprops->graphics_env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    if (sprops->font_dir != NULL) {
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 715
diff changeset
   290
        PUTPROP_ForPlatformNString(props,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                                   "sun.java2d.fontpath", sprops->font_dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 715
diff changeset
   294
    PUTPROP_ForPlatformNString(props, "java.io.tmpdir", sprops->tmp_dir);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 715
diff changeset
   296
    PUTPROP_ForPlatformNString(props, "user.name", sprops->user_name);
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 715
diff changeset
   297
    PUTPROP_ForPlatformNString(props, "user.home", sprops->user_home);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    PUTPROP(props, "user.timezone", sprops->timezone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 715
diff changeset
   301
    PUTPROP_ForPlatformNString(props, "user.dir", sprops->user_dir);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /* This is a sun. property as it is currently only set for Gnome and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Windows desktops.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    if (sprops->desktop != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        PUTPROP(props, "sun.desktop", sprops->desktop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   310
    /*
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6683
diff changeset
   311
     * unset "user.language", "user.script", "user.country", and "user.variant"
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   312
     * in order to tell whether the command line option "-DXXXX=YYYY" is
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   313
     * specified or not.  They will be reset in fillI18nProps() below.
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   314
     */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   315
    REMOVEPROP(props, "user.language");
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6683
diff changeset
   316
    REMOVEPROP(props, "user.script");
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   317
    REMOVEPROP(props, "user.country");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   318
    REMOVEPROP(props, "user.variant");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   319
    REMOVEPROP(props, "file.encoding");
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
    ret = JVM_InitProperties(env, props);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   322
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   323
    /* Check the compatibility flag */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   324
    GETPROP(props, "sun.locale.formatasdefault", jVMVal);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   325
    if (jVMVal) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   326
        const char * val = (*env)->GetStringUTFChars(env, jVMVal, 0);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   327
        fmtdefault = !strcmp(val, "true");
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   328
        (*env)->ReleaseStringUTFChars(env, jVMVal, val);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   329
        (*env)->DeleteLocalRef(env, jVMVal);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   330
    }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   331
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   332
    /* reconstruct i18n related properties */
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   333
    fillI18nProps(env, props, "user.language", sprops->display_language,
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   334
        sprops->format_language, putID, getPropID);
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6683
diff changeset
   335
    fillI18nProps(env, props, "user.script",
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 6683
diff changeset
   336
        sprops->display_script, sprops->format_script, putID, getPropID);
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   337
    fillI18nProps(env, props, "user.country",
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   338
        sprops->display_country, sprops->format_country, putID, getPropID);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   339
    fillI18nProps(env, props, "user.variant",
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   340
        sprops->display_variant, sprops->format_variant, putID, getPropID);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   341
    GETPROP(props, "file.encoding", jVMVal);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   342
    if (jVMVal == NULL) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   343
        if (fmtdefault) {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   344
            PUTPROP(props, "file.encoding", sprops->encoding);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   345
        } else {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   346
            PUTPROP(props, "file.encoding", sprops->sun_jnu_encoding);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   347
        }
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   348
    } else {
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   349
        (*env)->DeleteLocalRef(env, jVMVal);
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   350
    }
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
    return ret;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
 * The following three functions implement setter methods for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
 * java.lang.System.{in, out, err}. They are natively implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
 * because they violate the semantics of the language (i.e. set final
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
 * variable).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
Java_java_lang_System_setIn0(JNIEnv *env, jclass cla, jobject stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    jfieldID fid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        (*env)->GetStaticFieldID(env,cla,"in","Ljava/io/InputStream;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    if (fid == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    (*env)->SetStaticObjectField(env,cla,fid,stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
Java_java_lang_System_setOut0(JNIEnv *env, jclass cla, jobject stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    jfieldID fid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        (*env)->GetStaticFieldID(env,cla,"out","Ljava/io/PrintStream;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    if (fid == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    (*env)->SetStaticObjectField(env,cla,fid,stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
Java_java_lang_System_setErr0(JNIEnv *env, jclass cla, jobject stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    jfieldID fid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        (*env)->GetStaticFieldID(env,cla,"err","Ljava/io/PrintStream;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    if (fid == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    (*env)->SetStaticObjectField(env,cla,fid,stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
static void cpchars(jchar *dst, char *src, int n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    for (i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        dst[i] = src[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
JNIEXPORT jstring JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
Java_java_lang_System_mapLibraryName(JNIEnv *env, jclass ign, jstring libname)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    int prefix_len = (int) strlen(JNI_LIB_PREFIX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    int suffix_len = (int) strlen(JNI_LIB_SUFFIX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    jchar chars[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    if (libname == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        JNU_ThrowNullPointerException(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    len = (*env)->GetStringLength(env, libname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    if (len > 240) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        JNU_ThrowIllegalArgumentException(env, "name too long");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    cpchars(chars, JNI_LIB_PREFIX, prefix_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    (*env)->GetStringRegion(env, libname, 0, len, chars + prefix_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    len += prefix_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    cpchars(chars + len, JNI_LIB_SUFFIX, suffix_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    len += suffix_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    return (*env)->NewString(env, chars, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
}