From 6c1047f6fdd50e447b7886facb479dcf04f6b860 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 14 Feb 2020 09:47:09 +0000 Subject: ash: code shrink Commit 575581082 (ash: move code from setup_environment()) replaced calls to xsetenv_if_unset() with explicit tests. I don't know why because using xsetenv_if_unset() saves 48 bytes. --- shell/ash.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 3a143229e..1b7fa9849 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -14850,6 +14850,14 @@ exitshell(void) /* NOTREACHED */ } +#if ENABLE_PLATFORM_MINGW32 +static void xsetenv_if_unset(const char *key, const char *value) +{ + if (!getenv(key)) + xsetenv(key, value); +} +#endif + /* Don't inline: conserve stack of caller from having our locals too */ static NOINLINE void init(void) @@ -14943,10 +14951,10 @@ init(void) /* Initialise some variables normally set at login, but * only if someone hasn't already set them. */ pw = xgetpwuid(getuid()); - if (!getenv("USER")) xsetenv("USER", pw->pw_name); - if (!getenv("LOGNAME")) xsetenv("LOGNAME", pw->pw_name); - if (!getenv("HOME")) xsetenv("HOME", pw->pw_dir); - if (!getenv("SHELL")) xsetenv("SHELL", DEFAULT_SHELL); + xsetenv_if_unset("USER", pw->pw_name); + xsetenv_if_unset("LOGNAME", pw->pw_name); + xsetenv_if_unset("HOME", pw->pw_dir); + xsetenv_if_unset("SHELL", DEFAULT_SHELL); } #endif for (envp = environ; envp && *envp; envp++) { -- cgit v1.2.3-55-g6feb