summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2007-03-12 11:32:19 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:49:28 -0500
commitd464f0e78b63ee7df52df9171943f6a9723260fc (patch)
treeda8522e5160d9ea6e4bc431a3392ec680dc23ef7 /source4/lib
parentde75e93817da856f1e79f616e4fc09c27ab626c0 (diff)
downloadsamba-d464f0e78b63ee7df52df9171943f6a9723260fc.tar.gz
samba-d464f0e78b63ee7df52df9171943f6a9723260fc.tar.bz2
samba-d464f0e78b63ee7df52df9171943f6a9723260fc.zip
r21797: remove the key directly from the environ array
inspired by: http://cvs.linux-ha.org/viewcvs/viewcvs.cgi/linux-ha/replace/unsetenv.c?rev=1.4&view=auto metze (This used to be commit 8787525e518805f8445a376dc4964921598cb2e0)
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/replace/replace.c42
1 files changed, 17 insertions, 25 deletions
diff --git a/source4/lib/replace/replace.c b/source4/lib/replace/replace.c
index 486c1c5e13..03888a8eee 100644
--- a/source4/lib/replace/replace.c
+++ b/source4/lib/replace/replace.c
@@ -593,34 +593,26 @@ int rep_setenv(const char *name, const char *value, int overwrite)
#ifndef HAVE_UNSETENV
int rep_unsetenv(const char *name)
{
- char *p;
- size_t l1;
- int ret;
-
- if (!getenv(name)) {
- return 0;
- }
-
- l1 = strlen(name);
-
- p = malloc(l1+1);
- if (p == NULL) {
- return -1;
- }
- memcpy(p, name, l1);
- p[l1] = 0;
+ extern char **environ;
+ size_t len = strlen(name);
+ size_t i;
+ int found = 0;
+
+ for (i=0; (environ && environ[i]); i++) {
+ if (found) {
+ environ[i-1] = environ[i];
+ continue;
+ }
- /*
- * use using "name" here unsets the var
- *
- * "name=" would set it to an empty string..
- */
- ret = putenv(p);
- if (ret != 0) {
- free(p);
+ if (strncmp(environ[i], name, len) == 0 && environ[i][len] == '=') {
+ free(environ[i]);
+ environ[i] = NULL;
+ found = 1;
+ continue;
+ }
}
- return ret;
+ return 0;
}
#endif