diff options
author | Ron Yorston <rmy@pobox.com> | 2023-01-29 08:28:59 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-01-29 08:28:59 +0000 |
commit | 6295322661ac6c2ed90af69cba0003c6e37f9700 (patch) | |
tree | 44b70fdf880c37e5168ea16f2fa684b5debbadbc /win32/env.c | |
parent | 82f0d19b101271889b0b2ebe8cdb2f5eb4f64e6c (diff) | |
download | busybox-w32-6295322661ac6c2ed90af69cba0003c6e37f9700.tar.gz busybox-w32-6295322661ac6c2ed90af69cba0003c6e37f9700.tar.bz2 busybox-w32-6295322661ac6c2ed90af69cba0003c6e37f9700.zip |
win32: provide a default value for HOME
The busybox-w32 shell initialises HOME when it starts. However,
if applets are run outside the environment provided by the shell
they may find HOME is unset. This caused a problem for 'vi' as
it was unable to locate its .exrc.
If HOME isn't available in the environment make getenv(3) provide
a sensible default value. The shell must use the *real* getenv(3)
when determining if HOME is already set.
Also, unrelated to the above, the shell shouldn't treat failure of
getpwuid(3) as a fatal error.
Costs 72-80 bytes.
Diffstat (limited to 'win32/env.c')
-rw-r--r-- | win32/env.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/win32/env.c b/win32/env.c index 8e54c4c5e..f30ee62f6 100644 --- a/win32/env.c +++ b/win32/env.c | |||
@@ -6,11 +6,17 @@ | |||
6 | char *mingw_getenv(const char *name) | 6 | char *mingw_getenv(const char *name) |
7 | { | 7 | { |
8 | char *result = getenv(name); | 8 | char *result = getenv(name); |
9 | if (!result && !strcmp(name, "TMPDIR")) { | 9 | if (!result) { |
10 | /* on Windows it is TMP and TEMP */ | 10 | if (!strcmp(name, "TMPDIR")) { |
11 | result = getenv("TMP"); | 11 | /* on Windows it is TMP and TEMP */ |
12 | if (!result) | 12 | result = getenv("TMP"); |
13 | result = getenv("TEMP"); | 13 | if (!result) |
14 | result = getenv("TEMP"); | ||
15 | } else if (!strcmp(name, "HOME")) { | ||
16 | struct passwd *p = getpwuid(getuid()); | ||
17 | if (p) | ||
18 | result = p->pw_dir; | ||
19 | } | ||
14 | } | 20 | } |
15 | return result; | 21 | return result; |
16 | } | 22 | } |