mirror of
https://github.com/coreutils/coreutils.git
synced 2025-01-10 18:13:25 +08:00
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.
This commit is contained in:
parent
ebe74e183e
commit
e53732b471
12
src/env.c
12
src/env.c
@ -139,7 +139,6 @@ A mere - implies -i. If no COMMAND, print the resulting environment.\n\
|
|||||||
int
|
int
|
||||||
main (register int argc, register char **argv, char **envp)
|
main (register int argc, register char **argv, char **envp)
|
||||||
{
|
{
|
||||||
char *dummy_environ[1];
|
|
||||||
int optc;
|
int optc;
|
||||||
int ignore_environment = 0;
|
int ignore_environment = 0;
|
||||||
|
|
||||||
@ -171,12 +170,11 @@ main (register int argc, register char **argv, char **envp)
|
|||||||
if (optind < argc && !strcmp (argv[optind], "-"))
|
if (optind < argc && !strcmp (argv[optind], "-"))
|
||||||
ignore_environment = 1;
|
ignore_environment = 1;
|
||||||
|
|
||||||
environ = dummy_environ;
|
if (ignore_environment)
|
||||||
environ[0] = NULL;
|
{
|
||||||
|
static char *dummy_environ[] = { NULL };
|
||||||
if (!ignore_environment)
|
environ = dummy_environ;
|
||||||
for (; *envp; envp++)
|
}
|
||||||
putenv (*envp);
|
|
||||||
|
|
||||||
optind = 0; /* Force GNU getopt to re-initialize. */
|
optind = 0; /* Force GNU getopt to re-initialize. */
|
||||||
while ((optc = getopt_long (argc, argv, "+iu:", longopts, NULL)) != -1)
|
while ((optc = getopt_long (argc, argv, "+iu:", longopts, NULL)) != -1)
|
||||||
|
Loading…
Reference in New Issue
Block a user