Move the code that clears the environment when `-i' is specified, so it that

it does not happen until all single-letter options are processed.  This will
be important for the -S option, which will be coming soon.

Approved by:	re (blanket `env')
This commit is contained in:
Garance A Drosehn 2005-06-20 03:09:49 +00:00
parent f66e378b5e
commit 212274c3b6

14
usr.bin/env/env.c vendored
View File

@ -64,16 +64,14 @@ main(int argc, char **argv)
{
char **ep, *p, **parg;
char *cleanenv[1];
int ch;
int ch, want_clear;
want_clear = 0;
while ((ch = getopt(argc, argv, "-iv")) != -1)
switch(ch) {
case '-':
case 'i':
environ = cleanenv;
cleanenv[0] = NULL;
if (env_verbosity)
fprintf(stderr, "#env clearing environ\n");
want_clear = 1;
break;
case 'v':
env_verbosity++;
@ -85,6 +83,12 @@ main(int argc, char **argv)
default:
usage();
}
if (want_clear) {
environ = cleanenv;
cleanenv[0] = NULL;
if (env_verbosity)
fprintf(stderr, "#env clearing environ\n");
}
for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv) {
if (env_verbosity)
fprintf(stderr, "#env setenv:\t%s\n", *argv);