From ee091fc0cb85130715869bc8a349ad74d627dc95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 1 Aug 2008 17:58:04 +0000 Subject: [PATCH] * 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 --- src/system/libroot/posix/stdlib/env.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/system/libroot/posix/stdlib/env.c b/src/system/libroot/posix/stdlib/env.c index 052058567f..8e5e8cf5b8 100644 --- a/src/system/libroot/posix/stdlib/env.c +++ b/src/system/libroot/posix/stdlib/env.c @@ -26,7 +26,6 @@ // TODO: Use benaphore! static sem_id sEnvLock; static char **sManagedEnviron; -static bool sCopied; char **environ = NULL; @@ -82,14 +81,14 @@ static int32 add_variable(void) { int32 count = count_variables() + 1; - char **newEnv = realloc(environ, (count + 1) * sizeof(char *)); - if (newEnv == NULL) + char **newEnviron = realloc(environ, (count + 1) * sizeof(char *)); + if (newEnviron == NULL) return B_NO_MEMORY; - newEnv[count] = NULL; + newEnviron[count] = NULL; // null terminate the array - environ = sManagedEnviron = newEnv; + environ = sManagedEnviron = newEnviron; 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 copy_environ_to_heap_if_needed(void) { int32 i = 0; - if (sCopied && environ == sManagedEnviron) + if (environ == sManagedEnviron) return B_OK; if (sManagedEnviron != NULL) { @@ -143,7 +150,6 @@ copy_environ_to_heap_if_needed(void) // null terminate the array environ = sManagedEnviron; - sCopied = true; return B_OK; } @@ -222,6 +228,8 @@ clearenv(void) environ = NULL; unlock_variables(); + + return 0; }