classpath
[Top][All Lists]
Advanced

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

getenv()


From: Andrew Haley
Subject: getenv()
Date: Mon, 7 Jun 2004 16:07:28 +0100

Sun have seen the light,

Andrew.


2004-06-07  Andrew Haley  <address@hidden>

        * java/lang/System.java: (getenv0): New method.
        (getenv): Add security check.  Do the right thing.
        * java/lang/natSystem.cc (getenv0): New method.

Index: System.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/System.java,v
retrieving revision 1.14
diff -c -2 -p -r1.14 System.java
*** System.java 24 Sep 2003 01:56:56 -0000      1.14
--- System.java 7 Jun 2004 15:03:46 -0000
*************** public final class System
*** 452,467 ****
  
    /**
!    * This used to get an environment variable, but following Sun's lead,
!    * it now throws an Error. Use <code>getProperty</code> instead.
     *
     * @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
     */
    public static String getenv(String name)
    {
!     throw new Error("getenv no longer supported, use properties instead: "
!                     + name);
    }
  
--- 452,471 ----
  
    /**
!    * Gets the value of an environment variable.
     *
     * @param name the name of the environment variable
!    * @return the string value of the variable
!    * @throws NullPointerException
!    * @throws SecurityException if permission is denied
!    * @since 1.5
     */
    public static String getenv(String 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);
    }
  
*************** public final class System
*** 600,602 ****
--- 604,613 ----
     */
    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
Index: natSystem.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natSystem.cc,v
retrieving revision 1.56
diff -c -2 -p -r1.56 natSystem.cc
*** natSystem.cc        23 Jul 2003 15:31:43 -0000      1.56
--- natSystem.cc        7 Jun 2004 15:03:46 -0000
*************** java::lang::System::identityHashCode (jo
*** 131,134 ****
--- 131,148 ----
  }
  
+ 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);
+ }
+ 
  jboolean
  java::lang::System::isWordsBigEndian (void)




reply via email to

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