[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] System.getenv() implementation
From: |
Mark Wielaard |
Subject: |
[cp-patches] System.getenv() implementation |
Date: |
Sat, 28 Aug 2004 19:55:10 +0200 |
Hi all,
The following provides a real (reference) implementation of
(VM)System.getenv(). libgcj also has this and it is necessary when we
want the working TimeZone implementation from libgcj.
2004-08-28 Mark Wielaard <address@hidden>
* java/lang/System.java (getenv): Do security checks and call
VMSystem.getenv().
* vm/reference/java/lang/VMSystem.java (getenv): New static native
method.
* native/jni/java-lang/java_lang_VMSystem.c (getenv): New function.
* include/java_lang_VMSystem.h: Regenerated.
* NEWS: Mention new VMSystem.getenv() method and reference
implementation in Runtime Interface section.
If nobody objects I want to check this in when I import the new TimeZone
stuff. Note that this doesn't (yet?) delegates to the target native
layer since I wanted to wait till the new design was finished.
Cheers,
Mark
Index: NEWS
===================================================================
RCS file: /cvsroot/classpath/classpath/NEWS,v
retrieving revision 1.48
diff -u -r1.48 NEWS
--- NEWS 17 Aug 2004 02:55:08 -0000 1.48
+++ NEWS 28 Aug 2004 17:47:05 -0000
@@ -13,8 +13,13 @@
* Improved java.awt.image.BufferedImage support.
* AWT 1.0 event model support.
* GNU Classpath now comes with some example programs (see examples/README).
+
+Runtime interface Changes:
+
* java.lang.Compiler now uses the new java.lang.VMCompiler; there is
a reference implementation that most VMs can use.
+* java.lang.VMSystem has a new getenv(String) method and a reference C/JNI
+ implementation that should work on most Posix like systems.
New in release 0.10 (Jul 9, 2004)
Index: include/java_lang_VMSystem.h
===================================================================
RCS file: /cvsroot/classpath/classpath/include/java_lang_VMSystem.h,v
retrieving revision 1.4
diff -u -r1.4 java_lang_VMSystem.h
--- include/java_lang_VMSystem.h 28 May 2004 17:27:55 -0000 1.4
+++ include/java_lang_VMSystem.h 28 Aug 2004 17:47:05 -0000
@@ -17,6 +17,7 @@
JNIEXPORT void JNICALL Java_java_lang_VMSystem_setOut (JNIEnv *env, jclass,
jobject);
JNIEXPORT void JNICALL Java_java_lang_VMSystem_setErr (JNIEnv *env, jclass,
jobject);
JNIEXPORT jlong JNICALL Java_java_lang_VMSystem_currentTimeMillis (JNIEnv
*env, jclass);
+JNIEXPORT jstring JNICALL Java_java_lang_VMSystem_getenv (JNIEnv *env, jclass,
jstring);
#ifdef __cplusplus
}
Index: java/lang/System.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/System.java,v
retrieving revision 1.38
diff -u -r1.38 System.java
--- java/lang/System.java 23 Jul 2004 11:40:05 -0000 1.38
+++ java/lang/System.java 28 Aug 2004 17:47:05 -0000
@@ -584,18 +584,23 @@
}
/**
- * This used to get an environment variable, but following Sun's lead,
- * it now throws an Error. Use <code>getProperty</code> instead.
+ * Gets the value of an environment variable.
*
* @param name the name of the environment variable
- * @return this does not return
- * @throws Error this is not supported
- * @deprecated use address@hidden #getProperty(String)}; getenv is not
supported
+ * @return the string value of the variable or null when the
+ * environment variable is not defined.
+ * @throws NullPointerException
+ * @throws SecurityException if permission is denied
+ * @since 1.5
*/
public static String getenv(String name)
{
- throw new Error("getenv no longer supported, use properties instead: "
- + name);
+ if (name == null)
+ throw new NullPointerException();
+ SecurityManager sm = Runtime.securityManager; // Be thread-safe.
+ if (sm != null)
+ sm.checkPermission(new RuntimePermission("getenv." + name));
+ return VMSystem.getenv(name);
}
/**
Index: native/jni/java-lang/java_lang_VMSystem.c
===================================================================
RCS file:
/cvsroot/classpath/classpath/native/jni/java-lang/java_lang_VMSystem.c,v
retrieving revision 1.6
diff -u -r1.6 java_lang_VMSystem.c
--- native/jni/java-lang/java_lang_VMSystem.c 29 Apr 2004 06:42:15 -0000
1.6
+++ native/jni/java-lang/java_lang_VMSystem.c 28 Aug 2004 17:47:05 -0000
@@ -1,5 +1,5 @@
/* System.c -- native code for java.lang.System
- Copyright (C) 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -143,3 +143,20 @@
u.l = 1;
return (u.c[sizeof (long) - 1] == 1);
}
+
+JNIEXPORT jstring JNICALL
+Java_java_lang_VMSystem_getenv (JNIEnv *env, jclass klass, jstring jname)
+{
+ const char *cname;
+ const char *envname;
+
+ cname = JCL_jstring_to_cstring(env, jname);
+ if (cname == NULL)
+ return NULL;
+
+ envname = getenv(cname);
+ if (envname == NULL)
+ return NULL;
+
+ return (*env)->NewStringUTF(env, envname);
+}
Index: vm/reference/java/lang/VMSystem.java
===================================================================
RCS file: /cvsroot/classpath/classpath/vm/reference/java/lang/VMSystem.java,v
retrieving revision 1.10
diff -u -r1.10 VMSystem.java
--- vm/reference/java/lang/VMSystem.java 18 Dec 2002 14:09:45 -0000
1.10
+++ vm/reference/java/lang/VMSystem.java 28 Aug 2004 17:47:05 -0000
@@ -1,5 +1,5 @@
/* VMSystem.java -- helper for java.lang.system
- Copyright (C) 1998, 2002 Free Software Foundation
+ Copyright (C) 1998, 2002, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -172,4 +172,13 @@
return new PrintStream(new BufferedOutputStream(new
FileOutputStream(FileDescriptor.err)), true);
}
+ /**
+ * Gets the value of an environment variable.
+ * Always returning null is a valid (but not very useful) implementation.
+ *
+ * @param name The name of the environment variable (will not be null).
+ * @return The string value of the variable or null when the
+ * environment variable is not defined.
+ */
+ static native String getenv(String name);
}
signature.asc
Description: This is a digitally signed message part
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] System.getenv() implementation,
Mark Wielaard <=