classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] [generics] Patch: FYI: System.getenv


From: Tom Tromey
Subject: [cp-patches] [generics] Patch: FYI: System.getenv
Date: 02 Jan 2005 15:15:42 -0700

I'm checking this in on the generics branch.
It is an initial implementation of the new System.getenv method, plus
an implementation of the old one.

Tom

Index: ChangeLog
from  Tom Tromey  <address@hidden>

        * java/lang/System.java (getenv(String)): Rewrote.
        (getenv): New method.
        * vm/reference/java/lang/VMSystem.java (getenv): New methods.

Index: java/lang/System.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/System.java,v
retrieving revision 1.38.2.1
diff -u -r1.38.2.1 System.java
--- java/lang/System.java 9 Oct 2004 23:34:45 -0000 1.38.2.1
+++ java/lang/System.java 2 Jan 2005 22:15:50 -0000
@@ -1,5 +1,5 @@
 /* System.java -- useful methods to interface with the system
-   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004
+   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
    Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
@@ -43,6 +43,7 @@
 
 import java.io.InputStream;
 import java.io.PrintStream;
+import java.util.Map;
 import java.util.Properties;
 import java.util.PropertyPermission;
 
@@ -625,8 +626,21 @@
    */
   public static String getenv(String name)
   {
-    throw new Error("getenv no longer supported, use properties instead: "
-                    + name);
+    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
+    if (sm != null)
+      sm.checkPermission(new RuntimePermission("getenv." + name));
+    return VMSystem.getenv(name);
+  }
+
+  /**
+   * FIXME: document
+   */
+  public static Map<String, String> getenv()
+  {
+    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
+    if (sm != null)
+      sm.checkPermission(new RuntimePermission("getenv.*"));
+    return VMSystem.getenv();
   }
 
   /**
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 2 Jan 2005 22:15:51 -0000
@@ -1,5 +1,5 @@
 /* VMSystem.java -- helper for java.lang.system
-   Copyright (C) 1998, 2002 Free Software Foundation
+   Copyright (C) 1998, 2002, 2005 Free Software Foundation
 
 This file is part of GNU Classpath.
 
@@ -37,6 +37,7 @@
 
 package java.lang;
 
+import java.util.Map;
 import java.util.Properties;
 
 import java.io.*;
@@ -138,6 +139,21 @@
    public static native long currentTimeMillis();
 
   /**
+   * Return an unmodifiable Map representing the current environment.
+   */
+  static native Map<String, String> getenv();
+
+  /**
+   * Return a single element from the current environment.
+   */
+  static String getenv(String k)
+  {
+    // Inefficient but portable default implementation.
+    Map<String, String> m = getenv();
+    return m.get(k);
+  }
+
+  /**
    * Helper method which creates the standard input stream.
    * VM implementors may choose to construct these streams differently.
    * This method can also return null if the stream is created somewhere 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]