env-generic.cpp revision 804197ca1d56719343cd21af782ddc2c695a6760
/* $Id$ */
/** @file
* innotek Portable Runtime - Environment, Generic.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#if defined(RT_OS_WINDOWS)
# include <stdlib.h>
#else
# include <unistd.h>
#endif
#include <string.h>
struct RTENVINTERNAL
{
/* Array of environment variables. */
char **apszEnv;
/* Count of variables in the array. */
/* Capacity (real size) of the array. This includes space for the
* terminating NULL element (for compatibility with the C library), so
* that cCount <= cCapacity - 1. */
};
#define RTENV_GROW_SIZE 16
{
int rc;
/*
* Allocate environment handle.
*/
if (pIntEnv)
{
/*
* Pre-allocate the variable array.
*/
{
/* add terminating NULL */
return VINF_SUCCESS;
}
rc = VERR_NO_MEMORY;
}
else
rc = VERR_NO_MEMORY;
return rc;
}
/**
* Creates an empty environment block.
*
* @returns IPRT status code. Typical error is VERR_NO_MEMORY.
*
* @param pEnv Where to store the handle of the environment block.
*/
{
return VERR_INVALID_POINTER;
}
/**
* Destroys an environment block.
*
* @returns IPRT status code.
*
* @param Env Handle of the environment block.
*/
{
return VERR_INVALID_HANDLE;
{
}
return VINF_SUCCESS;
}
/**
* Creates an environment block and fill it with variables from the given
* environment array.
*
* @returns IPRT status code. Typical error is VERR_NO_MEMORY.
*
* @param pEnv Where to store the handle of the environment block.
* @param apszEnv Pointer to the NULL-terminated array of environment
* variables. If NULL, the current process' environment
* will be cloned.
*/
{
#ifndef RT_OS_L4 /* So far, our L4 libraries do not include environment support. */
/* count the number of varialbes to clone */
#else
#endif
struct RTENVINTERNAL *pIntEnv;
if (RT_FAILURE(rc))
return rc;
#ifndef RT_OS_L4
{
{
rc = VERR_NO_MEMORY;
break;
}
}
#endif
if (RT_SUCCESS(rc))
{
/* add terminating NULL */
return VINF_SUCCESS;
}
return rc;
}
{
/* free variables */
/* remove the hole */
if (cToMove)
/// @todo resize pIntEnv->apszEnv to a multiply of RTENV_GROW_SIZE to keep
/// it compact
/* add terminating NULL */
return VINF_SUCCESS;
}
{
int rc;
/* allocate a new variable array if needed */
if (apszEnv)
{
/* copy old variables */
/* initialize new variables with NULL */
/* replace the array */
if (needAlloc)
{
}
/* add terminating NULL */
return VINF_SUCCESS;
}
else
rc = VERR_NO_MEMORY;
return rc;
}
const char *pszValue)
{
size_t i = 0;
{
{
break;
}
}
/* allocate a new variable */
return VERR_NO_MEMORY;
{
/* replace the old variable */
return VINF_SUCCESS;
}
/* nothing to do to remove a non-existent variable */
return VINF_SUCCESS;
/* insert the new variable */
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
return rc;
}
/**
* Puts a 'variable=value' string into the environment.
*
* The supplied string must be in the current process' codepage.
* This function makes a copy of the supplied string.
*
* @returns IPRT status code. Typical error is VERR_NO_MEMORY.
*
* @param Env Handle of the environment block.
* @param pszVarEqualValue The variable '=' value string. If the value and '=' is
* omitted, the variable is removed from the environment.
*/
{
return VERR_INVALID_HANDLE;
if (pszVarEqualValue == NULL)
return VERR_INVALID_POINTER;
: strlen (pszVarEqualValue),
}
/**
* Returns a raw pointer to the array of environment variables of the given
* environment block where every variable is a string in format
* 'variable=value'.
*
* All returned strings are in the current process' codepage.
*
* @returns Pointer to the raw array of environment variables.
* @returns NULL if Env is NULL or invalid.
*
* @param Env Handle of the environment block.
*/
{
return NULL;
}