* clearenv() did not return anything, but should have returned 0 for success.
* sCopied wasn't needed anymore due to the sManagedEnviron variable. * Minor cleanup, added a description to copy_environ_to_heap_if_needed(). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26722 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -26,7 +26,6 @@
|
|||||||
// TODO: Use benaphore!
|
// TODO: Use benaphore!
|
||||||
static sem_id sEnvLock;
|
static sem_id sEnvLock;
|
||||||
static char **sManagedEnviron;
|
static char **sManagedEnviron;
|
||||||
static bool sCopied;
|
|
||||||
|
|
||||||
char **environ = NULL;
|
char **environ = NULL;
|
||||||
|
|
||||||
@@ -82,14 +81,14 @@ static int32
|
|||||||
add_variable(void)
|
add_variable(void)
|
||||||
{
|
{
|
||||||
int32 count = count_variables() + 1;
|
int32 count = count_variables() + 1;
|
||||||
char **newEnv = realloc(environ, (count + 1) * sizeof(char *));
|
char **newEnviron = realloc(environ, (count + 1) * sizeof(char *));
|
||||||
if (newEnv == NULL)
|
if (newEnviron == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
newEnv[count] = NULL;
|
newEnviron[count] = NULL;
|
||||||
// null terminate the array
|
// null terminate the array
|
||||||
|
|
||||||
environ = sManagedEnviron = newEnv;
|
environ = sManagedEnviron = newEnviron;
|
||||||
|
|
||||||
return count - 1;
|
return count - 1;
|
||||||
}
|
}
|
||||||
@@ -115,12 +114,20 @@ find_variable(const char *name, int32 length, int32 *_index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! Copies the environment from its current location into a heap managed
|
||||||
|
environment, if it's not already there.
|
||||||
|
|
||||||
|
This is needed whenever the environment is changed, that is, when one
|
||||||
|
of the POSIX *env() functions is called, and we either used the environment
|
||||||
|
provided by the kernel, or by an application that changed \c environ
|
||||||
|
directly.
|
||||||
|
*/
|
||||||
static status_t
|
static status_t
|
||||||
copy_environ_to_heap_if_needed(void)
|
copy_environ_to_heap_if_needed(void)
|
||||||
{
|
{
|
||||||
int32 i = 0;
|
int32 i = 0;
|
||||||
|
|
||||||
if (sCopied && environ == sManagedEnviron)
|
if (environ == sManagedEnviron)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
if (sManagedEnviron != NULL) {
|
if (sManagedEnviron != NULL) {
|
||||||
@@ -143,7 +150,6 @@ copy_environ_to_heap_if_needed(void)
|
|||||||
// null terminate the array
|
// null terminate the array
|
||||||
|
|
||||||
environ = sManagedEnviron;
|
environ = sManagedEnviron;
|
||||||
sCopied = true;
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,6 +228,8 @@ clearenv(void)
|
|||||||
environ = NULL;
|
environ = NULL;
|
||||||
|
|
||||||
unlock_variables();
|
unlock_variables();
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user