From 4e1c4de27a0ad5eb26df6fc78a2305992d15de4e Mon Sep 17 00:00:00 2001 From: gad Date: Mon, 20 Jun 2005 03:09:49 +0000 Subject: 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') --- usr.bin/env/env.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/usr.bin/env/env.c b/usr.bin/env/env.c index b4753b0..ebfdc98 100644 --- a/usr.bin/env/env.c +++ b/usr.bin/env/env.c @@ -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); -- cgit v1.1