annotate src/java.base/share/native/libjava/System.c @ 51151:1ddf9a99e4ad

Added tag jdk-11+28 for changeset 76072a077ee1
author jwilhelm
date Wed, 22 Aug 2018 21:50:12 +0200
parents b43edd41622d
children
rev   line source
duke@2 1 /*
psandoz@48081 2 * Copyright (c) 1994, 2017, Oracle and/or its affiliates. All rights reserved.
duke@2 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@2 4 *
duke@2 5 * This code is free software; you can redistribute it and/or modify it
duke@2 6 * under the terms of the GNU General Public License version 2 only, as
ohair@5506 7 * published by the Free Software Foundation. Oracle designates this
duke@2 8 * particular file as subject to the "Classpath" exception as provided
ohair@5506 9 * by Oracle in the LICENSE file that accompanied this code.
duke@2 10 *
duke@2 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@2 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@2 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@2 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@2 15 * accompanied this code).
duke@2 16 *
duke@2 17 * You should have received a copy of the GNU General Public License version
duke@2 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@2 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@2 20 *
ohair@5506 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@5506 22 * or visit www.oracle.com if you need additional information or have any
ohair@5506 23 * questions.
duke@2 24 */
duke@2 25
duke@2 26 #include <string.h>
duke@2 27
duke@2 28 #include "jni.h"
duke@2 29 #include "jni_util.h"
duke@2 30 #include "jvm.h"
duke@2 31 #include "java_props.h"
duke@2 32
duke@2 33 #include "java_lang_System.h"
duke@2 34
duke@2 35 #define OBJ "Ljava/lang/Object;"
duke@2 36
duke@2 37 /* Only register the performance-critical methods */
duke@2 38 static JNINativeMethod methods[] = {
duke@2 39 {"currentTimeMillis", "()J", (void *)&JVM_CurrentTimeMillis},
duke@2 40 {"nanoTime", "()J", (void *)&JVM_NanoTime},
duke@2 41 {"arraycopy", "(" OBJ "I" OBJ "II)V", (void *)&JVM_ArrayCopy},
duke@2 42 };
duke@2 43
duke@2 44 #undef OBJ
duke@2 45
duke@2 46 JNIEXPORT void JNICALL
duke@2 47 Java_java_lang_System_registerNatives(JNIEnv *env, jclass cls)
duke@2 48 {
duke@2 49 (*env)->RegisterNatives(env, cls,
duke@2 50 methods, sizeof(methods)/sizeof(methods[0]));
duke@2 51 }
duke@2 52
duke@2 53 JNIEXPORT jint JNICALL
duke@2 54 Java_java_lang_System_identityHashCode(JNIEnv *env, jobject this, jobject x)
duke@2 55 {
duke@2 56 return JVM_IHashCode(env, x);
duke@2 57 }
duke@2 58
alanb@22641 59 #define PUTPROP(props, key, val) \
alanb@22641 60 if (1) { \
alanb@22641 61 jstring jkey, jval; \
alanb@22641 62 jobject r; \
alanb@22641 63 jkey = (*env)->NewStringUTF(env, key); \
alanb@22641 64 if (jkey == NULL) return NULL; \
alanb@22641 65 jval = (*env)->NewStringUTF(env, val); \
alanb@22641 66 if (jval == NULL) return NULL; \
alanb@22641 67 r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \
alanb@22641 68 if ((*env)->ExceptionOccurred(env)) return NULL; \
alanb@22641 69 (*env)->DeleteLocalRef(env, jkey); \
alanb@22641 70 (*env)->DeleteLocalRef(env, jval); \
alanb@22641 71 (*env)->DeleteLocalRef(env, r); \
duke@2 72 } else ((void) 0)
duke@2 73
sherman@5168 74 /* "key" is a char type string with only ASCII character in it.
sherman@5168 75 "val" is a nchar (typedefed in java_props.h) type string */
sherman@5168 76
alanb@22641 77 #define PUTPROP_ForPlatformNString(props, key, val) \
alanb@22641 78 if (1) { \
alanb@22641 79 jstring jkey, jval; \
alanb@22641 80 jobject r; \
alanb@22641 81 jkey = (*env)->NewStringUTF(env, key); \
alanb@22641 82 if (jkey == NULL) return NULL; \
alanb@22641 83 jval = GetStringPlatform(env, val); \
alanb@22641 84 if (jval == NULL) return NULL; \
alanb@22641 85 r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \
alanb@22641 86 if ((*env)->ExceptionOccurred(env)) return NULL; \
alanb@22641 87 (*env)->DeleteLocalRef(env, jkey); \
alanb@22641 88 (*env)->DeleteLocalRef(env, jval); \
alanb@22641 89 (*env)->DeleteLocalRef(env, r); \
duke@2 90 } else ((void) 0)
alanb@22641 91 #define REMOVEPROP(props, key) \
alanb@22641 92 if (1) { \
alanb@22641 93 jstring jkey; \
alanb@22641 94 jobject r; \
alanb@22641 95 jkey = JNU_NewStringPlatform(env, key); \
alanb@22641 96 if (jkey == NULL) return NULL; \
alanb@22641 97 r = (*env)->CallObjectMethod(env, props, removeID, jkey); \
alanb@22641 98 if ((*env)->ExceptionOccurred(env)) return NULL; \
alanb@22641 99 (*env)->DeleteLocalRef(env, jkey); \
alanb@22641 100 (*env)->DeleteLocalRef(env, r); \
naoto@6489 101 } else ((void) 0)
alanb@22641 102 #define GETPROP(props, key, jret) \
alanb@22641 103 if (1) { \
alanb@22641 104 jstring jkey = JNU_NewStringPlatform(env, key); \
alanb@22641 105 if (jkey == NULL) return NULL; \
naoto@6489 106 jret = (*env)->CallObjectMethod(env, props, getPropID, jkey); \
alanb@22641 107 if ((*env)->ExceptionOccurred(env)) return NULL; \
alanb@22641 108 (*env)->DeleteLocalRef(env, jkey); \
naoto@6489 109 } else ((void) 0)
duke@2 110
simonis@48598 111 /* Third party may overwrite these values. */
simonis@48598 112 #ifndef VENDOR
ohair@6676 113 #define VENDOR "Oracle Corporation"
simonis@48598 114 #endif
simonis@48598 115 #ifndef VENDOR_URL
ohair@6676 116 #define VENDOR_URL "http://java.oracle.com/"
simonis@48598 117 #endif
simonis@48598 118 #ifndef VENDOR_URL_BUG
darcy@30819 119 #define VENDOR_URL_BUG "http://bugreport.java.com/bugreport/"
duke@2 120 #endif
duke@2 121
ohair@6676 122 #ifdef JAVA_SPECIFICATION_VENDOR /* Third party may NOT overwrite this. */
ohair@6676 123 #error "ERROR: No override of JAVA_SPECIFICATION_VENDOR is allowed"
ohair@6676 124 #else
ohair@6676 125 #define JAVA_SPECIFICATION_VENDOR "Oracle Corporation"
alanb@6850 126 #endif
lana@6683 127
naoto@6489 128 jobject fillI18nProps(JNIEnv *env, jobject props, char *baseKey,
naoto@6489 129 char *platformDispVal, char *platformFmtVal,
naoto@6489 130 jmethodID putID, jmethodID getPropID) {
naoto@6489 131 jstring jVMBaseVal = NULL;
naoto@6489 132
naoto@6489 133 GETPROP(props, baseKey, jVMBaseVal);
naoto@6489 134 if (jVMBaseVal) {
naoto@6489 135 // user specified the base property. there's nothing to do here.
naoto@6489 136 (*env)->DeleteLocalRef(env, jVMBaseVal);
naoto@6489 137 } else {
naoto@6489 138 char buf[64];
naoto@6489 139 jstring jVMVal = NULL;
naoto@6489 140 const char *baseVal = "";
naoto@6489 141
naoto@6489 142 /* user.xxx base property */
naoto@48928 143 if (platformDispVal) {
naoto@48928 144 PUTPROP(props, baseKey, platformDispVal);
naoto@48928 145 baseVal = platformDispVal;
naoto@6489 146 }
naoto@6489 147
naoto@6489 148 /* user.xxx.display property */
naoto@6489 149 jio_snprintf(buf, sizeof(buf), "%s.display", baseKey);
naoto@6489 150 GETPROP(props, buf, jVMVal);
naoto@6489 151 if (jVMVal == NULL) {
naoto@6489 152 if (platformDispVal && (strcmp(baseVal, platformDispVal) != 0)) {
naoto@6489 153 PUTPROP(props, buf, platformDispVal);
naoto@6489 154 }
naoto@6489 155 } else {
naoto@6489 156 (*env)->DeleteLocalRef(env, jVMVal);
naoto@6489 157 }
naoto@6489 158
naoto@6489 159 /* user.xxx.format property */
naoto@6489 160 jio_snprintf(buf, sizeof(buf), "%s.format", baseKey);
naoto@6489 161 GETPROP(props, buf, jVMVal);
naoto@6489 162 if (jVMVal == NULL) {
naoto@6489 163 if (platformFmtVal && (strcmp(baseVal, platformFmtVal) != 0)) {
naoto@6489 164 PUTPROP(props, buf, platformFmtVal);
naoto@6489 165 }
naoto@6489 166 } else {
naoto@6489 167 (*env)->DeleteLocalRef(env, jVMVal);
naoto@6489 168 }
naoto@6489 169 }
naoto@6489 170
naoto@6489 171 return NULL;
naoto@6489 172 }
naoto@6489 173
duke@2 174 JNIEXPORT jobject JNICALL
duke@2 175 Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props)
duke@2 176 {
duke@2 177 char buf[128];
alanb@22641 178 java_props_t *sprops;
alanb@22641 179 jmethodID putID, removeID, getPropID;
naoto@6489 180 jobject ret = NULL;
naoto@6489 181 jstring jVMVal = NULL;
duke@2 182
bchristi@48393 183 if ((*env)->EnsureLocalCapacity(env, 50) < 0) {
bchristi@48393 184 return NULL;
bchristi@48393 185 }
alanb@22641 186 sprops = GetJavaProperties(env);
alanb@22641 187 CHECK_NULL_RETURN(sprops, NULL);
alanb@22641 188
alanb@22641 189 putID = (*env)->GetMethodID(env,
alanb@22641 190 (*env)->GetObjectClass(env, props),
alanb@22641 191 "put",
alanb@22641 192 "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
alanb@22641 193 CHECK_NULL_RETURN(putID, NULL);
alanb@22641 194
alanb@22641 195 removeID = (*env)->GetMethodID(env,
alanb@22641 196 (*env)->GetObjectClass(env, props),
alanb@22641 197 "remove",
alanb@22641 198 "(Ljava/lang/Object;)Ljava/lang/Object;");
alanb@22641 199 CHECK_NULL_RETURN(removeID, NULL);
alanb@22641 200
alanb@22641 201 getPropID = (*env)->GetMethodID(env,
alanb@22641 202 (*env)->GetObjectClass(env, props),
alanb@22641 203 "getProperty",
alanb@22641 204 "(Ljava/lang/String;)Ljava/lang/String;");
alanb@22641 205 CHECK_NULL_RETURN(getPropID, NULL);
duke@2 206
duke@2 207 PUTPROP(props, "java.specification.version",
ihse@33984 208 VERSION_SPECIFICATION);
duke@2 209 PUTPROP(props, "java.specification.name",
duke@2 210 "Java Platform API Specification");
ohair@6676 211 PUTPROP(props, "java.specification.vendor",
ohair@6676 212 JAVA_SPECIFICATION_VENDOR);
duke@2 213
ihse@33984 214 PUTPROP(props, "java.version", VERSION_SHORT);
duke@2 215 PUTPROP(props, "java.vendor", VENDOR);
duke@2 216 PUTPROP(props, "java.vendor.url", VENDOR_URL);
duke@2 217 PUTPROP(props, "java.vendor.url.bug", VENDOR_URL_BUG);
duke@2 218
psandoz@48355 219 jio_snprintf(buf, sizeof(buf), "%d.%d", JVM_CLASSFILE_MAJOR_VERSION,
psandoz@48355 220 JVM_CLASSFILE_MINOR_VERSION);
duke@2 221 PUTPROP(props, "java.class.version", buf);
duke@2 222
duke@2 223 if (sprops->awt_toolkit) {
duke@2 224 PUTPROP(props, "awt.toolkit", sprops->awt_toolkit);
duke@2 225 }
dholmes@21130 226 #ifdef MACOSX
dholmes@21130 227 if (sprops->awt_headless) {
dholmes@21130 228 PUTPROP(props, "java.awt.headless", sprops->awt_headless);
dholmes@21130 229 }
dholmes@21130 230 #endif
duke@2 231
duke@2 232 /* os properties */
duke@2 233 PUTPROP(props, "os.name", sprops->os_name);
duke@2 234 PUTPROP(props, "os.version", sprops->os_version);
duke@2 235 PUTPROP(props, "os.arch", sprops->os_arch);
duke@2 236
vladidan@16041 237 #ifdef JDK_ARCH_ABI_PROP_NAME
vladidan@16041 238 PUTPROP(props, "sun.arch.abi", sprops->sun_arch_abi);
vladidan@16041 239 #endif
vladidan@16041 240
duke@2 241 /* file system properties */
duke@2 242 PUTPROP(props, "file.separator", sprops->file_separator);
duke@2 243 PUTPROP(props, "path.separator", sprops->path_separator);
duke@2 244 PUTPROP(props, "line.separator", sprops->line_separator);
duke@2 245
duke@2 246 /*
rriggs@49292 247 * file encoding for stdout and stderr
duke@2 248 */
sherman@11906 249 if (sprops->sun_stdout_encoding != NULL) {
sherman@11906 250 PUTPROP(props, "sun.stdout.encoding", sprops->sun_stdout_encoding);
sherman@11906 251 }
sherman@11906 252 if (sprops->sun_stderr_encoding != NULL) {
sherman@11906 253 PUTPROP(props, "sun.stderr.encoding", sprops->sun_stderr_encoding);
sherman@11906 254 }
sherman@11906 255
duke@2 256 /* unicode_encoding specifies the default endianness */
duke@2 257 PUTPROP(props, "sun.io.unicode.encoding", sprops->unicode_encoding);
duke@2 258 PUTPROP(props, "sun.cpu.isalist",
duke@2 259 (sprops->cpu_isalist ? sprops->cpu_isalist : ""));
duke@2 260 PUTPROP(props, "sun.cpu.endian", sprops->cpu_endian);
duke@2 261
michaelm@12047 262
michaelm@12047 263 #ifdef MACOSX
michaelm@12047 264 /* Proxy setting properties */
michaelm@12047 265 if (sprops->httpProxyEnabled) {
michaelm@12047 266 PUTPROP(props, "http.proxyHost", sprops->httpHost);
michaelm@12047 267 PUTPROP(props, "http.proxyPort", sprops->httpPort);
michaelm@12047 268 }
michaelm@12047 269
michaelm@12047 270 if (sprops->httpsProxyEnabled) {
michaelm@12047 271 PUTPROP(props, "https.proxyHost", sprops->httpsHost);
michaelm@12047 272 PUTPROP(props, "https.proxyPort", sprops->httpsPort);
michaelm@12047 273 }
michaelm@12047 274
michaelm@12047 275 if (sprops->ftpProxyEnabled) {
michaelm@12047 276 PUTPROP(props, "ftp.proxyHost", sprops->ftpHost);
michaelm@12047 277 PUTPROP(props, "ftp.proxyPort", sprops->ftpPort);
michaelm@12047 278 }
michaelm@12047 279
michaelm@12047 280 if (sprops->socksProxyEnabled) {
michaelm@12047 281 PUTPROP(props, "socksProxyHost", sprops->socksHost);
michaelm@12047 282 PUTPROP(props, "socksProxyPort", sprops->socksPort);
michaelm@12047 283 }
michaelm@12047 284
michaelm@12047 285 if (sprops->gopherProxyEnabled) {
michaelm@12047 286 // The gopher client is different in that it expects an 'is this set?' flag that the others don't.
michaelm@12047 287 PUTPROP(props, "gopherProxySet", "true");
michaelm@12047 288 PUTPROP(props, "gopherProxyHost", sprops->gopherHost);
michaelm@12047 289 PUTPROP(props, "gopherProxyPort", sprops->gopherPort);
michaelm@12047 290 } else {
michaelm@12047 291 PUTPROP(props, "gopherProxySet", "false");
michaelm@12047 292 }
michaelm@12047 293
michaelm@12047 294 // Mac OS X only has a single proxy exception list which applies
michaelm@12047 295 // to all protocols
michaelm@12047 296 if (sprops->exceptionList) {
michaelm@12047 297 PUTPROP(props, "http.nonProxyHosts", sprops->exceptionList);
michaelm@12047 298 PUTPROP(props, "ftp.nonProxyHosts", sprops->exceptionList);
michaelm@12047 299 PUTPROP(props, "socksNonProxyHosts", sprops->exceptionList);
michaelm@12047 300 }
michaelm@12047 301 #endif
michaelm@12047 302
sherman@5168 303 /* !!! DO NOT call PUTPROP_ForPlatformNString before this line !!!
rriggs@49292 304 * !!! The platform native encoding for strings has not been set up yet !!!
duke@2 305 */
rriggs@49121 306 InitializeEncoding(env, sprops->sun_jnu_encoding);
duke@2 307
duke@2 308 /* Printing properties */
duke@2 309 /* Note: java.awt.printerjob is an implementation private property which
duke@2 310 * just happens to have a java.* name because it is referenced in
ohair@6676 311 * a java.awt class. It is the mechanism by which the implementation
duke@2 312 * finds the appropriate class in the JRE for the platform.
duke@2 313 * It is explicitly not designed to be overridden by clients as
duke@2 314 * a way of replacing the implementation class, and in any case
duke@2 315 * the mechanism by which the class is loaded is constrained to only
duke@2 316 * find and load classes that are part of the JRE.
duke@2 317 * This property may be removed if that mechanism is redesigned
duke@2 318 */
duke@2 319 PUTPROP(props, "java.awt.printerjob", sprops->printerJob);
duke@2 320
duke@2 321 /* data model */
duke@2 322 if (sizeof(sprops) == 4) {
duke@2 323 sprops->data_model = "32";
duke@2 324 } else if (sizeof(sprops) == 8) {
duke@2 325 sprops->data_model = "64";
duke@2 326 } else {
duke@2 327 sprops->data_model = "unknown";
duke@2 328 }
duke@2 329 PUTPROP(props, "sun.arch.data.model", \
duke@2 330 sprops->data_model);
duke@2 331
duke@2 332 /* patch level */
duke@2 333 PUTPROP(props, "sun.os.patch.level", \
duke@2 334 sprops->patch_level);
duke@2 335
duke@2 336 /* Java2D properties */
duke@2 337 /* Note: java.awt.graphicsenv is an implementation private property which
duke@2 338 * just happens to have a java.* name because it is referenced in
ohair@6676 339 * a java.awt class. It is the mechanism by which the implementation
duke@2 340 * finds the appropriate class in the JRE for the platform.
duke@2 341 * It is explicitly not designed to be overridden by clients as
duke@2 342 * a way of replacing the implementation class, and in any case
duke@2 343 * the mechanism by which the class is loaded is constrained to only
duke@2 344 * find and load classes that are part of the JRE.
duke@2 345 * This property may be removed if that mechanism is redesigned
duke@2 346 */
duke@2 347 PUTPROP(props, "java.awt.graphicsenv", sprops->graphics_env);
duke@2 348 if (sprops->font_dir != NULL) {
sherman@5168 349 PUTPROP_ForPlatformNString(props,
duke@2 350 "sun.java2d.fontpath", sprops->font_dir);
duke@2 351 }
duke@2 352
sherman@5168 353 PUTPROP_ForPlatformNString(props, "java.io.tmpdir", sprops->tmp_dir);
duke@2 354
sherman@5168 355 PUTPROP_ForPlatformNString(props, "user.name", sprops->user_name);
sherman@5168 356 PUTPROP_ForPlatformNString(props, "user.home", sprops->user_home);
duke@2 357
duke@2 358 PUTPROP(props, "user.timezone", sprops->timezone);
duke@2 359
sherman@5168 360 PUTPROP_ForPlatformNString(props, "user.dir", sprops->user_dir);
duke@2 361
duke@2 362 /* This is a sun. property as it is currently only set for Gnome and
duke@2 363 * Windows desktops.
duke@2 364 */
duke@2 365 if (sprops->desktop != NULL) {
duke@2 366 PUTPROP(props, "sun.desktop", sprops->desktop);
duke@2 367 }
duke@2 368
naoto@6489 369 ret = JVM_InitProperties(env, props);
naoto@6489 370
naoto@6489 371 /* reconstruct i18n related properties */
naoto@6489 372 fillI18nProps(env, props, "user.language", sprops->display_language,
naoto@6489 373 sprops->format_language, putID, getPropID);
naoto@7017 374 fillI18nProps(env, props, "user.script",
naoto@7017 375 sprops->display_script, sprops->format_script, putID, getPropID);
naoto@6489 376 fillI18nProps(env, props, "user.country",
naoto@6489 377 sprops->display_country, sprops->format_country, putID, getPropID);
naoto@6489 378 fillI18nProps(env, props, "user.variant",
naoto@6489 379 sprops->display_variant, sprops->format_variant, putID, getPropID);
naoto@6489 380 GETPROP(props, "file.encoding", jVMVal);
naoto@6489 381 if (jVMVal == NULL) {
bchristi@15004 382 #ifdef MACOSX
bchristi@15004 383 /*
bchristi@15004 384 * Since sun_jnu_encoding is now hard-coded to UTF-8 on Mac, we don't
bchristi@15004 385 * want to use it to overwrite file.encoding
bchristi@15004 386 */
bchristi@15004 387 PUTPROP(props, "file.encoding", sprops->encoding);
bchristi@15004 388 #else
naoto@48928 389 PUTPROP(props, "file.encoding", sprops->sun_jnu_encoding);
bchristi@15004 390 #endif
naoto@6489 391 } else {
naoto@6489 392 (*env)->DeleteLocalRef(env, jVMVal);
naoto@6489 393 }
naoto@6489 394
rriggs@49121 395 // Platform defined encoding properties override any on the command line
rriggs@49121 396 PUTPROP(props, "sun.jnu.encoding", sprops->sun_jnu_encoding);
rriggs@49121 397
naoto@6489 398 return ret;
duke@2 399 }
duke@2 400
duke@2 401 /*
duke@2 402 * The following three functions implement setter methods for
duke@2 403 * java.lang.System.{in, out, err}. They are natively implemented
duke@2 404 * because they violate the semantics of the language (i.e. set final
duke@2 405 * variable).
duke@2 406 */
duke@2 407 JNIEXPORT void JNICALL
duke@2 408 Java_java_lang_System_setIn0(JNIEnv *env, jclass cla, jobject stream)
duke@2 409 {
duke@2 410 jfieldID fid =
duke@2 411 (*env)->GetStaticFieldID(env,cla,"in","Ljava/io/InputStream;");
duke@2 412 if (fid == 0)
duke@2 413 return;
duke@2 414 (*env)->SetStaticObjectField(env,cla,fid,stream);
duke@2 415 }
duke@2 416
duke@2 417 JNIEXPORT void JNICALL
duke@2 418 Java_java_lang_System_setOut0(JNIEnv *env, jclass cla, jobject stream)
duke@2 419 {
duke@2 420 jfieldID fid =
duke@2 421 (*env)->GetStaticFieldID(env,cla,"out","Ljava/io/PrintStream;");
duke@2 422 if (fid == 0)
duke@2 423 return;
duke@2 424 (*env)->SetStaticObjectField(env,cla,fid,stream);
duke@2 425 }
duke@2 426
duke@2 427 JNIEXPORT void JNICALL
duke@2 428 Java_java_lang_System_setErr0(JNIEnv *env, jclass cla, jobject stream)
duke@2 429 {
duke@2 430 jfieldID fid =
duke@2 431 (*env)->GetStaticFieldID(env,cla,"err","Ljava/io/PrintStream;");
duke@2 432 if (fid == 0)
duke@2 433 return;
duke@2 434 (*env)->SetStaticObjectField(env,cla,fid,stream);
duke@2 435 }
duke@2 436
duke@2 437 static void cpchars(jchar *dst, char *src, int n)
duke@2 438 {
duke@2 439 int i;
duke@2 440 for (i = 0; i < n; i++) {
duke@2 441 dst[i] = src[i];
duke@2 442 }
duke@2 443 }
duke@2 444
duke@2 445 JNIEXPORT jstring JNICALL
duke@2 446 Java_java_lang_System_mapLibraryName(JNIEnv *env, jclass ign, jstring libname)
duke@2 447 {
duke@2 448 int len;
duke@2 449 int prefix_len = (int) strlen(JNI_LIB_PREFIX);
duke@2 450 int suffix_len = (int) strlen(JNI_LIB_SUFFIX);
duke@2 451
duke@2 452 jchar chars[256];
duke@2 453 if (libname == NULL) {
duke@2 454 JNU_ThrowNullPointerException(env, 0);
duke@2 455 return NULL;
duke@2 456 }
duke@2 457 len = (*env)->GetStringLength(env, libname);
duke@2 458 if (len > 240) {
duke@2 459 JNU_ThrowIllegalArgumentException(env, "name too long");
duke@2 460 return NULL;
duke@2 461 }
duke@2 462 cpchars(chars, JNI_LIB_PREFIX, prefix_len);
duke@2 463 (*env)->GetStringRegion(env, libname, 0, len, chars + prefix_len);
duke@2 464 len += prefix_len;
duke@2 465 cpchars(chars + len, JNI_LIB_SUFFIX, suffix_len);
duke@2 466 len += suffix_len;
duke@2 467
duke@2 468 return (*env)->NewString(env, chars, len);
duke@2 469 }