jdk/src/share/native/java/lang/System.c
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 689 10d8df51c03a
child 5168 41e46b5d9b15
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 689
diff changeset
     2
 * Copyright 1994-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#define PUTPROP_ForPlatformCString(props, key, val) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    if (1) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        jstring jkey = JNU_NewStringPlatform(env, key); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        jstring jval = JNU_NewStringPlatform(env, val); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        jobject r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        if ((*env)->ExceptionOccurred(env)) return NULL; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        (*env)->DeleteLocalRef(env, jkey); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        (*env)->DeleteLocalRef(env, jval); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        (*env)->DeleteLocalRef(env, r); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    } else ((void) 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
#ifndef VENDOR /* Third party may overwrite this. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
#define VENDOR "Sun Microsystems Inc."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
#define VENDOR_URL "http://java.sun.com/"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
#define VENDOR_URL_BUG "http://java.sun.com/cgi-bin/bugreport.cgi"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
689
10d8df51c03a 6706299: System property java.class.version should be 51 for jdk7
sherman
parents: 2
diff changeset
    87
#define JAVA_MAX_SUPPORTED_VERSION 51
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
#define JAVA_MAX_SUPPORTED_MINOR_VERSION 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
JNIEXPORT jobject JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    char buf[128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    java_props_t *sprops = GetJavaProperties(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    jmethodID putID = (*env)->GetMethodID(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                                          (*env)->GetObjectClass(env, props),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                                          "put",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    if (sprops == NULL || putID == NULL ) return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    PUTPROP(props, "java.specification.version",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            JDK_MAJOR_VERSION "." JDK_MINOR_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    PUTPROP(props, "java.specification.name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            "Java Platform API Specification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    PUTPROP(props, "java.specification.vendor", "Sun Microsystems Inc.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    PUTPROP(props, "java.version", RELEASE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    PUTPROP(props, "java.vendor", VENDOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    PUTPROP(props, "java.vendor.url", VENDOR_URL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    PUTPROP(props, "java.vendor.url.bug", VENDOR_URL_BUG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    jio_snprintf(buf, sizeof(buf), "%d.%d", JAVA_MAX_SUPPORTED_VERSION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                                            JAVA_MAX_SUPPORTED_MINOR_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    PUTPROP(props, "java.class.version", buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    if (sprops->awt_toolkit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        PUTPROP(props, "awt.toolkit", sprops->awt_toolkit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /* os properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    PUTPROP(props, "os.name", sprops->os_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    PUTPROP(props, "os.version", sprops->os_version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    PUTPROP(props, "os.arch", sprops->os_arch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /* file system properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    PUTPROP(props, "file.separator", sprops->file_separator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    PUTPROP(props, "path.separator", sprops->path_separator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    PUTPROP(props, "line.separator", sprops->line_separator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *  user.language
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *  user.country, user.variant (if user's environment specifies them)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *  file.encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *  file.encoding.pkg
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    PUTPROP(props, "user.language", sprops->language);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    if (sprops->country) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        PUTPROP(props, "user.country", sprops->country);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    if (sprops->variant) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        PUTPROP(props, "user.variant", sprops->variant);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    PUTPROP(props, "file.encoding", sprops->encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    PUTPROP(props, "sun.jnu.encoding", sprops->sun_jnu_encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    PUTPROP(props, "file.encoding.pkg", "sun.io");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /* unicode_encoding specifies the default endianness */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    PUTPROP(props, "sun.io.unicode.encoding", sprops->unicode_encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    PUTPROP(props, "sun.cpu.isalist",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            (sprops->cpu_isalist ? sprops->cpu_isalist : ""));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    PUTPROP(props, "sun.cpu.endian",  sprops->cpu_endian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /* !!! DO NOT call PUTPROP_ForPlatformCString before this line !!!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * !!! I18n properties have not been set up yet !!!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /* Printing properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /* Note: java.awt.printerjob is an implementation private property which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * just happens to have a java.* name because it is referenced in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * a java.awt class. It is the mechanism by which the Sun implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * finds the appropriate class in the JRE for the platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * It is explicitly not designed to be overridden by clients as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * a way of replacing the implementation class, and in any case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * the mechanism by which the class is loaded is constrained to only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * find and load classes that are part of the JRE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * This property may be removed if that mechanism is redesigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    PUTPROP(props, "java.awt.printerjob", sprops->printerJob);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /* data model */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    if (sizeof(sprops) == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        sprops->data_model = "32";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    } else if (sizeof(sprops) == 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        sprops->data_model = "64";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        sprops->data_model = "unknown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    PUTPROP(props, "sun.arch.data.model",  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    sprops->data_model);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /* patch level */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    PUTPROP(props, "sun.os.patch.level",  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    sprops->patch_level);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /* Java2D properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /* Note: java.awt.graphicsenv is an implementation private property which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * just happens to have a java.* name because it is referenced in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * a java.awt class. It is the mechanism by which the Sun implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * finds the appropriate class in the JRE for the platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * It is explicitly not designed to be overridden by clients as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * a way of replacing the implementation class, and in any case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * the mechanism by which the class is loaded is constrained to only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * find and load classes that are part of the JRE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * This property may be removed if that mechanism is redesigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    PUTPROP(props, "java.awt.graphicsenv", sprops->graphics_env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    if (sprops->font_dir != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        PUTPROP_ForPlatformCString(props,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                                   "sun.java2d.fontpath", sprops->font_dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    PUTPROP_ForPlatformCString(props, "java.io.tmpdir", sprops->tmp_dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    PUTPROP_ForPlatformCString(props, "user.name", sprops->user_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    PUTPROP_ForPlatformCString(props, "user.home", sprops->user_home);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    PUTPROP(props, "user.timezone", sprops->timezone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    PUTPROP_ForPlatformCString(props, "user.dir", sprops->user_dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /* This is a sun. property as it is currently only set for Gnome and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Windows desktops.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    if (sprops->desktop != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        PUTPROP(props, "sun.desktop", sprops->desktop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    return JVM_InitProperties(env, props);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 * The following three functions implement setter methods for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 * java.lang.System.{in, out, err}. They are natively implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
 * because they violate the semantics of the language (i.e. set final
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 * variable).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
Java_java_lang_System_setIn0(JNIEnv *env, jclass cla, jobject stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    jfieldID fid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        (*env)->GetStaticFieldID(env,cla,"in","Ljava/io/InputStream;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    if (fid == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    (*env)->SetStaticObjectField(env,cla,fid,stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
Java_java_lang_System_setOut0(JNIEnv *env, jclass cla, jobject stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    jfieldID fid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        (*env)->GetStaticFieldID(env,cla,"out","Ljava/io/PrintStream;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    if (fid == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    (*env)->SetStaticObjectField(env,cla,fid,stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
Java_java_lang_System_setErr0(JNIEnv *env, jclass cla, jobject stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    jfieldID fid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        (*env)->GetStaticFieldID(env,cla,"err","Ljava/io/PrintStream;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    if (fid == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    (*env)->SetStaticObjectField(env,cla,fid,stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
static void cpchars(jchar *dst, char *src, int n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    for (i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        dst[i] = src[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
JNIEXPORT jstring JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
Java_java_lang_System_mapLibraryName(JNIEnv *env, jclass ign, jstring libname)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    int prefix_len = (int) strlen(JNI_LIB_PREFIX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    int suffix_len = (int) strlen(JNI_LIB_SUFFIX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    jchar chars[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    if (libname == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        JNU_ThrowNullPointerException(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    len = (*env)->GetStringLength(env, libname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    if (len > 240) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        JNU_ThrowIllegalArgumentException(env, "name too long");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    cpchars(chars, JNI_LIB_PREFIX, prefix_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    (*env)->GetStringRegion(env, libname, 0, len, chars + prefix_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    len += prefix_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    cpchars(chars + len, JNI_LIB_SUFFIX, suffix_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    len += suffix_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    return (*env)->NewString(env, chars, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
}