env-posix.cpp revision dbc6ecd6a6e372b8dcdf31d68bdab2d5b5e604d2
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * IPRT - Environment, Posix.
dbc6ecd6a6e372b8dcdf31d68bdab2d5b5e604d2vboxsync * Copyright (C) 2006-2014 Oracle Corporation
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.
c39e02bbf326184d8f70d4d6f4fbceb8ea5b6b97vboxsync/*******************************************************************************
c39e02bbf326184d8f70d4d6f4fbceb8ea5b6b97vboxsync* Header Files *
c39e02bbf326184d8f70d4d6f4fbceb8ea5b6b97vboxsync*******************************************************************************/
37c0e44bde09575588c7c31f768e9a85293423efvboxsync/* pick the correct prototype for unsetenv. */
dbc6ecd6a6e372b8dcdf31d68bdab2d5b5e604d2vboxsyncRTDECL(const char *) RTEnvGetBad(const char *pszVar)
223b7220b8ccc3642433776c4c9d07e01448254cvboxsync IPRT_ALIGNMENT_CHECKS_DISABLE(); /* glibc causes trouble */
dbc6ecd6a6e372b8dcdf31d68bdab2d5b5e604d2vboxsyncRTDECL(int) RTEnvPutBad(const char *pszVarEqualValue)
739c77783387df1b22501b27bd870869a865d20cvboxsync /** @todo putenv is a source memory leaks. deal with this on a per system basis. */
dbc6ecd6a6e372b8dcdf31d68bdab2d5b5e604d2vboxsyncRTDECL(int) RTEnvSetBad(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. */
dbc6ecd6a6e372b8dcdf31d68bdab2d5b5e604d2vboxsyncRTDECL(int) RTEnvSet(const char *pszVar, const char *pszValue)
ababd7e83ee3d23c5191a0d3802f10764df69e36vboxsync AssertReturn(!strchr(pszVar, '='), VERR_INVALID_PARAMETER);
4a4a02cc2a09b5e3c55908c6995182c6b038e398vboxsync * Check that it exists first.
4a4a02cc2a09b5e3c55908c6995182c6b038e398vboxsync * Ok, try remove it.
4a4a02cc2a09b5e3c55908c6995182c6b038e398vboxsync /* Use putenv(var=) since Windows does not have unsetenv(). */
8556cbc7d613d44c2d31260928bd71d17feb492fvboxsync /* This is the preferred function as putenv() like used above does neither work on Solaris nor on Darwin. */