env-posix.cpp revision e593c0cb11d4eccdc28dcf82c9b8aac46c631371
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * IPRT - Environment, Posix.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
c39e02bbf326184d8f70d4d6f4fbceb8ea5b6b97vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
c39e02bbf326184d8f70d4d6f4fbceb8ea5b6b97vboxsync * available from http://www.virtualbox.org. This file is free software;
c39e02bbf326184d8f70d4d6f4fbceb8ea5b6b97vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * The contents of this file may alternatively be used under the terms
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * of the Common Development and Distribution License Version 1.0
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution, in which case the provisions of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * CDDL are applicable instead of those of the GPL.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * You may elect to license modified versions of this file under the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * terms and conditions of either the GPL or the CDDL or both.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * additional information or have any questions.
c39e02bbf326184d8f70d4d6f4fbceb8ea5b6b97vboxsync/*******************************************************************************
c39e02bbf326184d8f70d4d6f4fbceb8ea5b6b97vboxsync* Header Files *
c39e02bbf326184d8f70d4d6f4fbceb8ea5b6b97vboxsync*******************************************************************************/
e593c0cb11d4eccdc28dcf82c9b8aac46c631371vboxsync/*XXX: see sys/cdefs.h */
739c77783387df1b22501b27bd870869a865d20cvboxsync /** @todo putenv is a source memory leaks. deal with this on a per system basis. */
739c77783387df1b22501b27bd870869a865d20cvboxsyncRTDECL(int) RTEnvSet(const char *pszVar, const char *pszValue)
739c77783387df1b22501b27bd870869a865d20cvboxsync /* make a local copy and feed it to putenv. */
739c77783387df1b22501b27bd870869a865d20cvboxsync char *pszTmp = (char *)alloca(cchVar + cchValue + 2 + !*pszValue);
739c77783387df1b22501b27bd870869a865d20cvboxsync memcpy(pszTmp + cchVar + 1, pszValue, cchValue + 1);
739c77783387df1b22501b27bd870869a865d20cvboxsync pszTmp[cchVar + 1] = ' '; /* wrong, but putenv will remove it otherwise. */
ababd7e83ee3d23c5191a0d3802f10764df69e36vboxsync AssertReturn(!strchr(pszVar, '='), VERR_INVALID_PARAMETER);
ababd7e83ee3d23c5191a0d3802f10764df69e36vboxsync /* Check that it exists first. */
ababd7e83ee3d23c5191a0d3802f10764df69e36vboxsync /* Ok, try remove it. */
8556cbc7d613d44c2d31260928bd71d17feb492fvboxsync /* Windows does not have unsetenv(). Clear the environment variable according to the MSN docs. */
8556cbc7d613d44c2d31260928bd71d17feb492fvboxsync /* This is the preferred function as putenv() like used above does neither work on Solaris nor on Darwin. */