summaryrefslogtreecommitdiff
path: root/source4/lib/replace/replace.c
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/replace/replace.c')
-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