3909N/A * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A/* We use APIs that access the standard Unix environ array, which 0N/A * is defined by UNIX98 to look like: 0N/A * These are unsorted, case-sensitive, null-terminated arrays of bytes 0N/A * of the form FOO=BAR\000 which are usually encoded in the user's 0N/A * default encoding (file.encoding is an excellent choice for 0N/A * directly access the underlying byte representation, we take pains 0N/A * to pass on the child the exact byte representation we inherit from 0N/A * the parent process for any environment name or value not created by 0N/A * Javaland. So we keep track of all the byte representations. 0N/A * Internally, we define the types Variable and Value that exhibit 0N/A * environment then looks like a Map<Variable,Value>. But we don't 0N/A * expose this to the user -- we only provide a Map<String,String> 0N/A * view, although we could also provide a Map<byte[],byte[]> view. 0N/A * The non-private methods in this class are not for general use even 0N/A * within this package. Instead, they are the system-dependent parts 0N/A * of the system-independent method of the same name. Don't even 0N/A * think of using this class unless your method's name appears below. 0N/A * @author Martin Buchholz 0N/A // We cache the C environment. This means that subsequent calls 0N/A // Read environment variables back to front, 0N/A // so that earlier variables override later ones. 0N/A /* Only for use by System.getenv(String) */ 0N/A /* Only for use by System.getenv() */ 0N/A /* Only for use by ProcessBuilder.environment() */ 0N/A /* Only for use by Runtime.exec(...String[]envp...) */ 0N/A // This class is not instantiable. 0N/A // Check that name is suitable for insertion into Environment map 0N/A (
"Invalid environment variable name: \"" +
name +
"\"");
0N/A // Check that value is suitable for insertion into Environment map 0N/A (
"Invalid environment variable value: \"" +
value +
"\"");
0N/A // A class hiding the byteArray-String duality of 0N/A // text data on Unixoid operating systems. 0N/A // This implements the String map view the user sees. 0N/A // It is technically feasible to provide a byte-oriented view 0N/A // public Map<byte[],byte[]> asByteArrayMap() { 0N/A // return new ByteArrayEnvironment(m); 0N/A // Convert to Unix style environ as a monolithic byte array 0N/A // inspired by the Windows Environment Block, except we work 0N/A // exclusively with bytes instead of chars, and we need only 0N/A // one trailing NUL on Unix. 0N/A // This keeps the JNI as simple and efficient as possible. 0N/A // No need to write NUL byte explicitly 0N/A //block[i++] = (byte) '\u0000'; 0N/A // Replace with general purpose method someday 0N/A // Replace with general purpose method someday 0N/A // Replace with general purpose method someday