summaryrefslogtreecommitdiff
path: root/src/env.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-06-03 08:29:41 +0000
committerJim Meyering <jim@meyering.net>2003-06-03 08:29:41 +0000
commite53732b471a06467b7e8c7c16860a7f023770b4c (patch)
tree6b589b44b14035158744c8d82b0898bb7b56f742 /src/env.c
parentebe74e183ea1e7a2635540d0a31bee358b3e7aa9 (diff)
downloadcoreutils-e53732b471a06467b7e8c7c16860a7f023770b4c.tar.xz
Avoid unnecessary copying of environment.
(main): Rather than clearing the environment and -- unless told to ignore environment -- copying all settings from the saved, original environment, clear the environment only when that is requested. Suggested by Jens Elkner.
Diffstat (limited to 'src/env.c')
-rw-r--r--src/env.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/env.c b/src/env.c
index 2db3ad6dd..c6879aed5 100644
--- a/src/env.c
+++ b/src/env.c
@@ -139,7 +139,6 @@ A mere - implies -i. If no COMMAND, print the resulting environment.\n\
int
main (register int argc, register char **argv, char **envp)
{
- char *dummy_environ[1];
int optc;
int ignore_environment = 0;
@@ -171,12 +170,11 @@ main (register int argc, register char **argv, char **envp)
if (optind < argc && !strcmp (argv[optind], "-"))
ignore_environment = 1;
- environ = dummy_environ;
- environ[0] = NULL;
-
- if (!ignore_environment)
- for (; *envp; envp++)
- putenv (*envp);
+ if (ignore_environment)
+ {
+ static char *dummy_environ[] = { NULL };
+ environ = dummy_environ;
+ }
optind = 0; /* Force GNU getopt to re-initialize. */
while ((optc = getopt_long (argc, argv, "+iu:", longopts, NULL)) != -1)