2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 2N/A/* All Rights Reserved */ 2N/A#
pragma ident "%Z%%M% %I% %E% SMI" 2N/A * xsetenv, xgetenv, Xgetenv - manage an alternate environment space 2N/A * int ret = xsetenv(file) 2N/A * char *x = xgetenv("FOO"); 2N/A * char *x = Xgetenv("FOO"); 2N/A * xsetenv() reads the given file into an internal buffer 2N/A * and sets up an alternate environment. 2N/A * Return values: 1 - OKAY 2N/A * 0 - troubles reading the file 2N/A * -1 - troubles opening the file 2N/A * xgetenv() returns the environment value from the 2N/A * alternate environment. 2N/A * Return values: (char *)0 - no value for that variable 2N/A * pointer - the value 2N/A * Xgetenv() returns the environment value from the 2N/A * alternate environment. 2N/A * Return values: "" - no value for that variable 2N/A * pointer - the value 2N/A * Assumes the environment is < 5120 bytes, as in the UNIX 2N/A * System environment. Assumes < 512 lines in the file. 2N/A * These values may be adjusted below. 2N/A * set up an environment buffer 2N/A * and the pointers into it 2N/A /* Read in the entire file. */ 2N/A * Set up pointers into the buffer. 2N/A * Replace \n with \0. 2N/A * Collapse white space around the = sign and at the 2N/A * beginning and end of the line. 2N/A * Let getenv() do the dirty work 2N/A * of looking up the variable. We 2N/A * do this by temporarily resetting 2N/A * environ to point to the local area. 2N/A * Let xgetenv() do the dirty work 2N/A * of looking up the variable. 2N/A * Remove the spaces within the environment variable. 2N/A * The variable can look like this: 2N/A * <sp1> variable <sp2> = <sp3> value <sp4> \0 2N/A * All spaces can be removed, except within 2N/A * the variable name and the value.