env-generic.cpp revision c58f1213e628a545081c70e26c6b67a841cff880
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * IPRT - Environment, Generic.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * Copyright (C) 2006-2012 Oracle Corporation
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * available from http://www.virtualbox.org. This file is free software;
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * you can redistribute it and/or modify it under the terms of the GNU
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * General Public License (GPL) as published by the Free Software
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * The contents of this file may alternatively be used under the terms
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * of the Common Development and Distribution License Version 1.0
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * VirtualBox OSE distribution, in which case the provisions of the
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * CDDL are applicable instead of those of the GPL.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * You may elect to license modified versions of this file under the
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * terms and conditions of either the GPL or the CDDL or both.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync/*******************************************************************************
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync* Header Files *
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync*******************************************************************************/
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync#if defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD) || defined(RT_OS_OPENBSD)
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsyncextern char **environ;
94e4227f21b6d46df0f75f5cd1f2edf16b71ef26vboxsync/*******************************************************************************
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync* Defined Constants And Macros *
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync*******************************************************************************/
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync/** Macro that unlocks the specified environment block. */
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync/** Macro that unlocks the specified environment block. */
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsync/*******************************************************************************
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsync* Structures and Typedefs *
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync*******************************************************************************/
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsync * The internal representation of a (non-default) environment.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync /** Magic value . */
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync /** Number of variables in the array.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * This does not include the terminating NULL entry. */
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsync /** Capacity (allocated size) of the array.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * This includes space for the terminating NULL element (for compatibility
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsync * with the C library), so that c <= cCapacity - 1. */
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsync /** Array of environment variables. */
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsync /** Array of environment variables in the process CP.
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsync * This get (re-)constructed when RTEnvGetExecEnvP method is called. */
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync/** The allocation granularity of the RTENVINTERNAL::papszEnv memory. */
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsync * Internal worker that resolves the pointer to the default
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * process environment. (environ)
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsync * @returns Pointer to the default environment.
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsync * This may be NULL.
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsyncstatic const char * const *rtEnvDefault(void)
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsync /* So far, our L4 libraries do not include environment support. */
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * Internal worker that creates an environment handle with a specified capacity.
if (pIntEnv)
return VINF_SUCCESS;
return VERR_NO_MEMORY;
return VINF_SUCCESS;
while (iVar-- > 0)
return VINF_SUCCESS;
const char * const *papszEnv;
cVars = 0;
if (papszEnv)
cVars++;
iDst++;
return rc2;
return VERR_NO_STR_MEMORY;
if (pIntEnvToClone)
return rc;
int rc;
if (!pszEq)
return rc;
int rc;
char *pszVarOtherCP;
char *pszValueOtherCP;
if (pszEntry)
void *pvNew = RTMemRealloc(pIntEnv->papszEnv, sizeof(char *) * (pIntEnv->cAllocated + RTENV_GROW_SIZE));
if (!pvNew)
return rc;
int rc;
char *pszVarOtherCP;
return rc;
RTDECL(int) RTEnvGetEx(RTENV Env, const char *pszVar, char *pszValue, size_t cbValue, size_t *pcchActual)
if (pcchActual)
*pcchActual = 0;
int rc;
char *pszVarOtherCP;
if (pszValueOtherCP)
char *pszValueUtf8;
if (pcchActual)
if (pcchActual)
return rc;
bool fExist = false;
char *pszVarOtherCP;
fExist = true;
return fExist;
const char * const *papszRet;
if (!papszRet)
char **papsz;
papszRet = pIntEnv->papszEnvOtherCP = papsz = (char **)RTMemAlloc(sizeof(char *) * (pIntEnv->cVars + 1));
if (papsz)
return papszRet;
if (iDiff < 0)
else if (iDiff > 0)
return iDiff;
int rc;
return rc;
if (pwszz)
return rc;