diff options
author | aph <aph@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-06-14 14:34:21 +0000 |
---|---|---|
committer | aph <aph@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-06-14 14:34:21 +0000 |
commit | 611d57f3241cb4eee320e205f3d695a3c8d21a2e (patch) | |
tree | f2966e59c9f3c09ec6484a7f905e07de8c1416ae /libjava/java | |
parent | 2e9da478edf45047e522074479ad7646cb4c4e68 (diff) | |
download | gcc-611d57f3241cb4eee320e205f3d695a3c8d21a2e.tar.gz |
2004-06-14 Andrew Haley <aph@redhat.com>
* java/lang/System.java: (getenv0): New method.
(getenv): Add security check. Do the right thing.
* java/lang/natSystem.cc (getenv0): New method.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@83107 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java')
-rw-r--r-- | libjava/java/lang/System.java | 25 | ||||
-rw-r--r-- | libjava/java/lang/natSystem.cc | 13 |
2 files changed, 31 insertions, 7 deletions
diff --git a/libjava/java/lang/System.java b/libjava/java/lang/System.java index 1d9805bc145..d7529871845 100644 --- a/libjava/java/lang/System.java +++ b/libjava/java/lang/System.java @@ -454,18 +454,22 @@ public final class System } /** - * 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 {@link #getProperty(String)}; getenv is not supported + * @return the string value of the variable + * @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 getenv0(name); } /** @@ -602,4 +606,11 @@ public final class System * @see #setErr(PrintStream) */ private static native void setErr0(PrintStream err); + + /** + * Gets the value of an environment variable. + * + * @see #getenv(String) + */ + static native String getenv0(String name); } // class System diff --git a/libjava/java/lang/natSystem.cc b/libjava/java/lang/natSystem.cc index 4a08bb138bf..ffb26a3cf80 100644 --- a/libjava/java/lang/natSystem.cc +++ b/libjava/java/lang/natSystem.cc @@ -142,3 +142,16 @@ java::lang::System::isWordsBigEndian (void) u.lval = 1; return u.cval == 0; } + +jstring +java::lang::System::getenv0 (jstring name) +{ + jint len = _Jv_GetStringUTFLength (name); + char buf[len + 1]; + jsize total = JvGetStringUTFRegion (name, 0, name->length(), buf); + buf[total] = '\0'; + const char *value = ::getenv (buf); + if (value == NULL) + return NULL; + return JvNewStringLatin1 (value); +} |