aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-08-15 09:09:57 -0500
committerRob Landley <rob@landley.net>2015-08-15 09:09:57 -0500
commitc82be78035e536b2b2248be6d6f3cd5a995f11f1 (patch)
tree56aaa64070790e9d9f67e67fc120dfa63c1c9749 /toys
parent1ed524277be6916b00858b8f983ba812dfae48e6 (diff)
downloadtoybox-c82be78035e536b2b2248be6d6f3cd5a995f11f1.tar.gz
Kylie McClain pointed out that env should clear variables with NAME= by itself.
Diffstat (limited to 'toys')
-rw-r--r--toys/posix/env.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/toys/posix/env.c b/toys/posix/env.c
index f20517eb..87c25a01 100644
--- a/toys/posix/env.c
+++ b/toys/posix/env.c
@@ -24,16 +24,17 @@ extern char **environ;
void env_main(void)
{
char **ev;
- char *del = "=";
if (toys.optflags) clearenv();
- for (ev = toys.optargs; *ev != NULL; ev++) {
- char *env = strtok(*ev, del), *val = 0;
+ for (ev = toys.optargs; *ev; ev++) {
+ char *name = *ev, *val = strchr(name, '=');
- if (env) val = strtok(0, del);
- if (val) setenv(env, val, 1);
- else xexec(ev);
+ if (val) {
+ *(val++) = 0;
+ if (*val) setenv(name, val, 1);
+ else unsetenv(name);
+ } else xexec(ev);
}
if (environ) for (ev = environ; *ev; ev++) xputs(*ev);